字符串替换(find函数和replace函数)

#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
while(true)
{
getline(cin, str);
if(cin.eof()) break;
int index;
while(true)
{
index = str.find("you");
if(index == string::npos) break;
str.replace(index, 3, "we", 2);
}
cout<<str<<endl;
}
return 0;
}

原文地址:https://www.cnblogs.com/cwenliu/p/5928117.html