美文网首页
container-string-插入、删除、截取应用

container-string-插入、删除、截取应用

作者: 人不知QAQ | 来源:发表于2019-08-29 17:00 被阅读0次

#include <iostream>

using namespace std;

#include <string>

void test01()

{

string  str1 = "hello";

str1.insert(1, "qq");

cout << str1 << endl;//插入

str1.erase(1, 2);

cout << str1 << endl;//删除

string  str = "abcdef";//截取

string subStr = str.substr(1, 3);

cout << subStr << endl;

}

void  test02()//截取应用

{

string email = "zhansan@singa.com";

//得到用户名

int pos = email.find("@");

string subStr = email.substr(0,pos);

cout << subStr << endl;

}

int main()

{

test01();

test02();

system("pause");

return 0;

}

相关文章

网友评论

      本文标题:container-string-插入、删除、截取应用

      本文链接:https://www.haomeiwen.com/subject/gngiectx.html