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
}

结果:

STL容器之string插入和删除

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2021-06-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-07-23
  • 2022-12-23
  • 2021-11-26
相关资源
相似解决方案