您的位置:首页 > 编程语言 > C语言/C++

C++ Primer 课后联系9.44

2016-12-06 19:27 381 查看
9.44
#include
#include
using namespace std;
void oops_func(string & s1,const string & s2,const string & s3);
int main(void)
{
string s = "Rachel Monica Joey Chandler Phobe";
string newval = "Ross";
string oldval = "Monica";
cout << s << endl;
oops_func(s, oldval, newval);
cout << s << endl;
return 0;
}
void oops_func(string & s1,const string & s2,const string & s3)
{

for (int i = 0; i <= s1.size(); i++)
{
if (s1.substr(i, s2.size()) == s2)
{
s1.replace(i, s2.size(), s3);
i += s3.size() - 1;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: