花了一会总算搞明白了,供参考
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s = "520love";
int a = stoi(s); //把字符串s转化成整数,s必须以数字开头,但不必以数字结尾
cout << a << endl; //520
int b = stoi(s, nullptr, 16);//把16进制的520转化为10进制
cout << b << endl; //1312
size_t pos;
int c = stoi(s, &pos); //pos是字符串s中第一个非数字元素的位置
cout << pos << endl; //3
cout << s.substr(pos) << endl; //love
cout << s.substr(pos, 2) << endl; //lo
}