码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-10-02 22:01:38      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!