replace()用法

todaycode發表於2020-10-21
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str = "abcdef";
	str.replace(0,3,"XXX");
	cout << str << endl;       //輸出: XXXdef
	str.replace(0, 3, 3, 'Y');
	cout << str << endl;	   //輸出: YYYdef
	string s = "2020";
	str.replace(0, 3, s, 0, 3);
	cout << str << endl;       //輸出: 202def
	return 0;
}

 

相關文章