您的位置:首页 > 编程语言 > C语言/C++

强大的C++模板编程,任意类型间轻松转换

2012-03-22 11:30 204 查看
#include <sstream>
#include <string>
template<class T> //任意类型转字符型
void my_tostring(std::wstring & result, const T& type)
{
std::wstringstream oss;
oss<<type;
result = oss.str();
}
template<class out_type, class in_value> //任意类型转任意类型
out_type my_convert(const in_value &type)
{
std::stringstream stream;
stream<<type;
out_type result;
stream>>result;
return result;
}

std::wstring rtstr;

my_tostring(rtstr,11.5);

int reti = my_convert<int>("150");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: