作用:

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

头文件:

#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

 参考:

http://www.cplusplus.com/reference/string/stoi/

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2021-11-12
  • 2021-08-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2023-03-23
  • 2021-12-09
  • 2022-02-05
  • 2022-12-23
  • 2021-10-11
相关资源
相似解决方案