字符串分割(2)

#include <iostream>
#include <string>
using namespace std;
int main() {
	
	string str="雷猴,我是李玉波,我今年上八年级;";
	//replace是替换的意思
	//一个汉字是两个字符 
	str=str.replace(str.find("李"),6,"陈若麟");
	str=str.replace(str.find("八"),6,"七年级");
	cout<<str<<endl;
	
	string str="he is@ a@ good boy";
	str=str.replace(str.begin(),str.begin()+5,"#");
	cout<<str<<endl;
	
	string str="he is@ a@ good boy";
	char*str1="12345";
	str=str.replace(0,6,str1,4);
	cout<<str<<endl;
	return 0;}

  

posted @ 2022-10-29 20:18  chenruolin1  阅读(6)  评论(0编辑  收藏  举报