C++ examples for STL:string
Insert a phrase at insertion point
#include <string> #include <cstdlib> #include <cstdio> #include <iostream> using namespace std; string insertPhrase(const string& source) { string s = source;/* w w w . j a va2s.co m*/ size_t offset = s.find("<ip>"); if (offset != string::npos) { s.erase(offset, 4); s.insert(offset, "Randall"); } return s; } int main(int argc, char* pArgs[]) { string s3 = "asdf <ip> adsf"; cout << s3 + " -> " + insertPhrase(s3) << endl; return 0; }