首页 > 其他 > 详细

string子串(12)

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

功能描述:

  • 从字符串中获取想要的子串

函数原型:

string substr(int pos = 0, int n = npos) const;   //返回由pos开始的n个字符组成的字符串

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 
 5 void test_01()
 6 {
 7     string email = "shuaige@sina.com";
 8     string usrname;
 9     int pos = email.find("@");
10     usrname = email.substr(0, pos);
11     cout << usrname << endl;
12 }
13 
14 int main(void)
15 {
16     test_01();
17 
18     system("pause");
19     return 0;
20 
21 }

 

string子串(12)

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

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