Difference between revisions of "CPP/Strings/FindAndReplace"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==FindAndReplace.cpp== <source lang="cpp"> #include <iostream> #include <string> int main(int argc, char *argv[]) { std::string sentence = "hello world test"; std::string w…')
 
(No difference)

Latest revision as of 11:54, 19 September 2010

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)