原文地址: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;
}

相关文章:

  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2021-08-01
  • 2022-12-23
  • 2021-09-17
  • 2021-07-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案