c++ string 转 int

来源:互联网 发布:安全阀计算软件 编辑:程序博客网 时间:2024/06/11 03:49

转自http://blog.csdn.net/caroline_wendy/article/details/29390573



C语言转换形式:

[plain] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. ...  
  2. std::string str;  
  3. int i = atoi(str.c_str());  
  4. ...  


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

[plain] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. ...  
  2. std::string str;  
  3. int i = std::stoi(str);  
  4. ...  

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


int 转string   c++11的to_string函数

1 0
原创粉丝点击