0
点赞
收藏
分享

微信扫一扫

stringstream 用法以及清空内部数据

头文件

#include <sstream>

简单用法

  std::stringstream ssTest;
ssTest << "welcome to https://blog.51cto.com/fengyuzaitu" << std::endl;
std::cout << ssTest.str();

高阶用法

​​https://blog.51cto.com/fengyuzaitu/2047650​​​ ​​​​​

​​https://blog.51cto.com/fengyuzaitu/1735334​​

清除内部数据

clear函数并不能清理数据

  std::stringstream ssTest;
ssTest << "welcome to https://blog.51cto.com/fengyuzaitu" << std::endl;
ssTest.clear();
std::cout << ssTest.str();

必须使用str("")

  std::stringstream ssTest;
ssTest << "welcome to https://blog.51cto.com/fengyuzaitu" << std::endl;
ssTest.str("");
ssTest << "welcome to https://blog.51cto.com/fengyuzaitu" << std::endl;
std::cout << ssTest.str();


举报

相关推荐

0 条评论