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;
}
}
}
本文通过一个C++示例展示了如何进行字符串操作。示例中使用了标准库中的字符串类型,并定义了一个函数用于处理字符串。虽然代码片段不完整,但可以看出作者试图演示如何修改字符串变量。
6244

被折叠的 条评论
为什么被折叠?



