C/C++ string类型转换int类型

来源:互联网 发布:北京金山软件年终奖 编辑:程序博客网 时间:2024/06/11 05:49

string类型转换int类型


原文地址: http://blog.csdn.NET/caroline_wendy


C语言转换形式:

[plain] view plain copy
print?
  1. ...  
  2. std::string str;  
  3. int i = atoi(str.c_str());  
  4. ...  


C++转换形式(C++11):

[plain] view plain copy
print?
  1. ...  
  2. std::string str;  
  3. int i = std::stoi(str);  
  4. ...  

同样, 可以使用 stol(long), stof(float), stod(double) 等.


参考: http://en.cppreference.com/w/cpp/string/basic_string/stol



阅读全文
0 0
原创粉丝点击