C++ Primer 课后联系9.44

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
		}
	}
	
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值