欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

理解C++11的stoi函数 - cppreference文档解析

最编程 2024-01-12 20:41:10
...
#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;
}