C++中stoi函数

做用:

  将 n 进制的字符串转化为十进制ios

头文件:

#include <string>

用法:

1 stoi(字符串,起始位置,n进制),将 n 进制的字符串转化为十进制 2 
3  示例: 4 stoi(str, 0, 2); //将字符串 str 从 0 位置开始到末尾的 2 进制转换为十进制

但好像不是标准函数,慎用吧。函数

案例:

 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;  5 
 6 int main()  7 {  8     string str = "1010";  9     int a = stoi(str, 0, 2); 10     cout << a << endl; 11         return 0; 12 }

输出结果:

10

参考:

https://blog.csdn.net/CV2017/article/details/85164019spa

相关文章
相关标签/搜索