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().
上一篇: 短信验证码的实现