功能描述:

    • 对string字符串进行插入和删除字符操作

    函数原型:

    1. string& insert(int pos, const char * s); //插入字符串
    2. string& insert(int pos, const string & str); //插入字符串
    3. string& insert(int pos, int n, char c); //在指定位置插入n个字符c
    4. string& erase(int pos, int n = npos); //删除从pos开始的n个字符
    1. // 字符串 插入和删除
    2. void test01()
    3. {
    4. string str = "hello";
    5. //插入
    6. str.insert(1, "111");
    7. cout << "str = " << str << endl;
    8. //删除
    9. str.erase(1, 3);
    10. cout << "str = " << str << endl;
    11. }
    12. int main(void)
    13. {
    14. test01();
    15. system("pause");
    16. return 0;
    17. }