理解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;
}
#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;
}
上一篇: C++刷题必备:STL容器全攻略
下一篇: stoi函数在C++中的应用解析