#include #include int main() { std::string buf1; std::ostringstream formatter1(buf1); std::string buf2; std::ostringstream formatter2; formatter2.str(buf2); formatter1 << "Hello World # " << 1 << "\n\nMORE\n"; formatter2 << std::hex; formatter2 << 10 << "|" << 20 << "|" << 30; std::cout << "===========================================================\n"; std::string tmp; // returns a std::string by value tmp = formatter1.str(); std::cout << tmp; std::cout << "===========================================================\n"; std::cout << formatter2.str() << "\n"; std::cout << "===========================================================\n"; return 0; }