#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");
强大的C++模板编程,任意类型间轻松转换
最新推荐文章于 2024-08-13 17:36:14 发布