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

时间:2014-06-11 00:27:22   收藏:0   阅读:294

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


bubuko.com,布布扣

C++ - string类型转换int类型,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!