首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

在C++中怎么将int bool double转化为string和将string 转化为int bool double

2012-04-19 
在C++中如何将int bool double转化为string和将string 转化为intbool double在C++中如何将intbooldouble转

在C++中如何将int bool double转化为string和将string 转化为int bool double
在C++中如何将int   bool   double转化为string和将string   转化为int     bool   double

[解决办法]
#include <sstream>

template <class T>
std::string tostring(T t)
{
std::ostringstream os;
os < <t;
return std::string(os.str());
}
template <class T>
T fromstring(std::string& s)
{
T t;
std::istringstream is(s);
is> > t;
return t;
}

[解决办法]
参考《exceptional C++ style》item2, item3

热点排行