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

来源:互联网 发布:计量经济学第四版数据 编辑:程序博客网 时间:2024/06/05 15:44

string类型转换int类型


本文地址: http://blog.csdn.net/caroline_wendy


C语言转换形式:

...std::string str;int i = atoi(str.c_str());...


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

...std::string str;int i = std::stoi(str);...

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


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



10 0
原创粉丝点击