首页 > 其他 > 详细

string存入和删除(11)

时间:2020-07-09 13:22:06      阅读:65      评论:0      收藏:0      [点我收藏+]

功能描述:

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

函数原型:

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个字符

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 
 5 void test_01()
 6 {
 7     string str1 = "hello";
 8 
 9     //插入
10     //str1.append(" world");
11     str1.insert(5, " world!");
12     cout << str1 << endl;
13 
14     //删除
15     str1.erase(6, 12);
16     cout << str1 << endl;
17 }
18 
19 int main(void)
20 {
21     test_01();
22 
23     system("pause");
24     return 0;
25 
26 }

 

string存入和删除(11)

原文:https://www.cnblogs.com/huanian/p/13272926.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!