流类型clear()的坑!

PS:c++ clear()在流中时标识清空所有标记! 而不是像在string中时清空字符串.

在STL容器里clear方法的含义均为清空容器,但在STL的所有流中clear的含义均为清空错误标记!

那么问题来了。。。如何清除呢?

       oss.str("");

string str ( ) const;    // returns a copy of the string object currently associated with the string stream buffer.

void str ( const string & s ); // copies the content of string s to the string object associated with the string stream buffer. The function effectivelly calls rdbuf()->str(). Notice that setting a new string does not clear the error flags currently set in the stream object unless the member function clear is explicitly called.

ostringstream.str()方法,尽量控制不必要的重复调用,这可能会带来性能问题。

原文地址:https://www.cnblogs.com/lthuang/p/12097109.html