// stringstream2.cc #include #include using namespace std; int main() { int t = 4, result = 42; stringstream ss; ss << "Try " << t << " gave a value of " << result; cout << ss.str() << endl; // convert to string for printing // Let's reuse the stringstream. Reset it by replacing // the string it contains with a blank one. ss.str(std::string()); ss << "Hello, world!"; cout << ss.str() << endl; }