函数原型:
string substr(int pos=0;int n=npos)
#include<iostream>
using namespace std;
#include<string>
void test01()
{
string str1 = "hello";
string sub=str1.substr(1, 3);//ell
cout << sub << endl;
}
void test02()
{
//实用案例
string email = "lisi@qq.com";
int pos = email.find("@");
cout << pos << endl;
string usename = email.substr(0, pos);
cout << usename << endl;
}
int main()
{
//test01();
test02();
system("pause");
return 0;
}
const;//返回由pos开始的n个字符组成的字符串