pku3981

真是服了自己了,一个简单的字符串替换搞了半天……………………

C++还是不太会

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	while(getline(cin,str))
	{
		//getchar();
		string::size_type pos = 0;
		string str1="you";
		 while ((pos=str.find(str1,pos)) != string::npos)//若查找失败,返回string::npos 
		{
			str.replace(pos,str1.size(),"we");
				pos++;
		 }
		 cout<<str<<endl;
	}
	return 0;
}
posted @ 2011-07-30 15:41  枕边梦  阅读(158)  评论(0编辑  收藏  举报