欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ostringstream 的清空数据方法

程序员文章站 2022-05-19 19:25:52
...

关于C++中 <sstream>中ostringstream的清空方法。

 

ostringstream outString;
outString.str("");//清空数据

 

   容易混淆的是,outString.clear()//清空错误的标志位

 

   outString.str()有种两种用法,Get/set the associated string object (public member function)

 

 1、string str ( ) const;//获取当前字符串

 2、void str ( const string & s );//设置当前数据流为该字符串s

 

The first version returns a copy of the string object currently associated with the string stream buffer.

The second syntax copies the content of string s to the string object associated with the string stream buffer. The function effectivelly calls rdbuf()->str().