stringstream 用法以及清空内部数据

东林梁

关注

阅读 105

2022-11-10

头文件

#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)

0 0 举报