#include<iostream>
#include<string>
using namespace std;
int main()
{
string word = "abcdefgh";
string a = word.substr(1);
string b = word.substr(3, 5);
cout << "a: " << a << endl;
cout << "b: " << b << endl;
return 0;
}
输出结果:
a: bcdefgh
b: defgh
用法:
1、s.substr(pos, n);从下标为pos开始截取长度为n的字符串
2、s.substr(n);从下标为n开始一直到末尾的字符串