string replace

原文地址:http://www.java2s.com/Code/Cpp/Data-Type/StringFindandreplace.htm

#include <string> 
#include <iostream>

using namespace std;

int main()
{
    string str"a bc abc abcd abcde" );
    string searchString"hello" )
    string replaceString"ab" );

    assertsearchString != replaceString );

    string::size_type pos = 0;
    while ( (pos = str.find(searchString, pos)) != string::npos ) {
        str.replacepos, searchString.size(), replaceString );
        pos++;
    }
    cout << str << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/wangkangluo1/p/2166673.html