关于某个类型转字符串和字符串转换某种类型的简单实现(用字符串流)

template<typename T>
T from_string(
const std::string &s)
{
    std::istringstream 
is(s);
    T type;
    
is >> type;
    
return t;
}

template
<typename T>
std::
string to_string(const T &type)
{
    std::ostringstream s;
    s 
<< type;
    
return s.str();
}

直接用字符串流方便的处理了各种内嵌类型


做个标记,回家了

posted on 2011-06-09 18:22 Hallelujah 阅读(257) 评论(0)  编辑 收藏 引用 所属分类: C++学习

<2025年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿(1)

随笔分类(15)

随笔档案(14)

最新随笔

搜索

最新随笔

最新评论

阅读排行榜

评论排行榜