CPP/Strings/FindAndReplace
From ProgrammingExamples
< CPP
FindAndReplace.cpp
#include <iostream> #include <string> int main(int argc, char *argv[]) { std::string sentence = "hello world test"; std::string wordToReplace = "world"; std::string replaceWith = "mars"; sentence.replace(sentence.find(wordToReplace), wordToReplace.size(), replaceWith); std::cout << sentence; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(FindAndReplace) ADD_EXECUTABLE(FindAndReplace FindAndReplace.cpp)