ITeye博客

ostringstream 的清空数据方法

qimo601 · 2012-09-27 15:28 · C/C++ · 编程语言 · Markdown

关于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().

评论(1)

  1. #1 楼 · sitonmoon · 2015-01-23 09:25

    :D 很好 不过代码选成Java代码

评论功能维护中,当前仅展示历史评论。