Possible duplicate:How to reuse ostringstream?
I used std::ostringstreamto transform the values floatand intin line, but I still can not reuse copy. To illustrate what I mean here, the following along with the methods that I tried to use to clear the stream
std::ostringstream
float
int
#include <iostream> #include <sstream> using namespace std; int main() { ostringstream stream; stream << "Test"; cout << stream.str() << endl; stream.flush(); stream << "----"; cout << stream.str() << endl; stream.clear(); stream << "****"; cout << stream.str() << endl; return 0; }
generates output
Test Test---- Test----****
, ostringstream, . , clear() flush() , , ? http://www.cplusplus.com/reference/iostream/ostringstream/, , , . reset ?
ostringstream
clear()
flush()
stream.str("");, . , . ++ , , , , :
stream.str("");
{ std::ostringstream oss; oss << 10; std::cout << oss.str(); } { std::ostringstream oss; oss << 20.5; std::cout << oss.str(); }
:
std::cout << static_cast<std::ostringstream&>(std::ostringstream() << 10).str();
clear() . . str() :
str()
, .