C++ examples for STL:string
Replace a sub string with another sub string using iterator
#include <iostream> #include <string> #include <cctype> #include <algorithm> #include <vector> using namespace std; int main()//from w w w .ja v a 2s . c o m { string strA("This is a test. another test test test"); // Create an iterator to a string. string::iterator itr; // Now, replace 'bigger' with 'larger'. cout << "Replace bigger with larger.\n"; itr = find(strA.begin(), strA.end(), 'b'); strA.replace(itr, itr+6, "larger"); cout << strA << "\n\n"; return 0; }