int       stoi( const std::string& str, std::size_t* pos = 0, int base = 10 );
int stoi( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
(1) (C++11 起)
long stol( const std::string& str, std::size_t* pos = 0, int base = 10 );
long stol( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
(2) (C++11 起)
long long stoll( const std::string& str, std::size_t* pos = 0, int base = 10 );
long long stoll( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
(3) (C++11 起)
str - 要
转换的字符串
pos - 存储已处理字符数的整数的地址,pos如果不为空,则会返回一个字符串中遇到的第一个字符(非数字)的字符下标,最后一个base是默认10进制。
base - 数的底
#include <iostream>
#include <string>
using namespace std;

#define debug(x) cout<<#x<<": "<<(x)<<endl;

bool test(string s,int base=0) {
size_t pos = 3;
cout << s << ": " << stoi(s,&pos, base) << endl;
debug(pos)
debug(s.substr(pos))
return true;
}

int main() {

// 若 base 为 0 ,则自动检测数值进制
test("0x1azzzz",0);
test("017zzzz",0);
test("017abcdefghijk",16);
test("017zzzz",15);

return 0;
}
0x1azzzz: 26
pos: 4
s.substr(pos): zzzz
017zzzz: 15
pos: 3
s.substr(pos): zzzz
017abcdefghijk: 397135343
pos: 9
s.substr(pos): ghijk
017zzzz: 22
pos: 3
s.substr(pos): zzzz