string子串(12)
功能描述:
- 从字符串中获取想要的子串
函数原型:
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 }