BZ易风

导航

 

1.

/*
插入和删除操作
string& insert(int pos, const char* s); //插入字符串
string& insert(int pos, const string& str); //插入字符串
string& insert(int pos, int n, char c);//在指定位置插入n个字符c
string& erase(int pos, int n = npos);//删除从Pos开始的n个字符
*/
void test02()
{
    string s1 = "hello";
    //插入
    s1.insert(1, "123");    //string& insert(int pos, const char* s);
    cout << s1 << endl;     //h123ello

    //删除
    s1.erase(1, 3);
    cout << s1 << endl;     //hello
}

结果:

 

posted on 2021-08-26 13:24  BZ易风  阅读(160)  评论(0编辑  收藏  举报