The "str()" and "str( string )" methods should work.
However, on some platforms these may not work so you
may use the ugly reconstruct hack.
#include <sstream>
#include <iostream>
int main()
{
std::istringstream iss( "Hi there" );
std:
stringstream oss;
std::string foo;
iss >> foo;
oss << foo;
iss.str( "boo hoo" ); // Set the input to new string
iss >> foo;
oss << foo;
std::cout << oss.str() << "\n";
// Another way is to reconstruct the istringstream
// UGLY but some implementations have bugs and this is the
// only way.
iss.~istringstream();
new ( (void *) &iss ) std::istringstream( "Reconstruct this" );
oss.str( "" ); // reset the output string.
iss >> foo;
oss << foo;
std::cout << oss.str() << "\n";
// Another way is to reconstruct the ostringstream
oss.~ostringstream();
new ( (void *) &oss ) std:
stringstream;
iss >> foo;
oss << foo;
std::cout << oss.str() << "\n";
}