描述
编写一个程序实现将字符串中的所有"you"替换成"we"
you are what you do
//Asimple
#include <iostream>
#include <string>
using namespace std;
string str, s1="you", s2="we";
int main()
{
int pos;
while( getline(cin,str) )
{
pos = str.find(s1,0);
while( pos != string::npos )
{
str.replace(pos,3,s2);
pos = str.find(s1,pos+1);
}
cout << str << endl ;
}
return 0;
}
原文:http://www.cnblogs.com/Asimple/p/5506507.html