作用:
将 n 进制的字符串转化为十进制
头文件:
#include <string>
用法:
11 stoi(字符串,起始位置,n进制),将 n 进制的字符串转化为十进制 22 33 示例: 44 stoi(str, 0, 2); //将字符串 str 从 0 位置开始到末尾的 2 进制转换为十进制
但好像不是标准函数,慎用吧。
案例:
1 1 #include <iostream> 2 2 #include <string> 3 3 4 4 using namespace std; 5 5 6 6 int main() 7 7 { 8 8 string str = "1010"; 9 9 int a = stoi(str, 0, 2); 1010 cout << a << endl; 1111 return 0; 1212 }
输出结果:
10