您的位置:首页 > 其它

std::string与int、double相互转换

2010-05-18 16:56 459 查看
std::string为library type,而int、double为built-in type,两者无法互转。

方法一,使用function template的方式将int转std::string,将double转std:string。

代码

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main() {
string s = "123";
double n = atof(s.c_str());
//int n = atoi(s.c_str());

cout << n << endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: