insert()函数
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str("Hello World.");
string a,b;
a = str.insert(4, "sky");
//在下标为4的位置,插入字符串sky
cout << a << endl;//输出Hellskyo World.
str="Hello World.";
b = str.insert(4, 5, 'x');
//在下标为4的位置,插入字符串5个x
cout << b << endl;//输出Hellxxxxxo World.
return 0;
}
erase()函数
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str("Hello World.");
string a,b;
a = str.erase(4,5);
//删除从下标4开始的5个字符
cout << a << endl;//输出Hellld.
return 0;
}