首页 > 其他 > 详细

sstream

时间:2019-12-27 11:04:45      阅读:89      评论:0      收藏:0      [点我收藏+]

比较常用的是这个 stringstream,用来转换数据贼方便,比起sscanf和sprintf来说更好用。

<sstream>库定义了三种类:istringstream、ostringstream和stringstream,分别用来进行流的输入、输出和输入输出操作。

  1.stringstream::str(); returns a string object with a copy of the current contents of the stream.

  2.stringstream::str (const string& s); sets s as the contents of the stream, discarding any previous contents.

  3.stringstream清空,stringstream s; s.str("");

  4.实现任意类型的转换

    template<typename out_type, typename in_value>
    out_type convert(const in_value & t){
      stringstream stream;
      stream<<t;//向流中传值
      out_type result;//这里存储转换结果
      stream>>result;//向result中写入值
      return result;
    }

 

对于stringstream判断空,可以if(stringstream>>str){//进入这里说明不为空,反之亦然}

sstream

原文:https://www.cnblogs.com/zzqc/p/12105750.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!