... double: "};
14 string string4{"\n int: "};
15 string string5{"\naddress of int: "};
16
17 double double1{123.4567};
18 int integer{22};
19
20 // output strings, double and int to ostringstream outputString
21 outputString << string1 << string2 << string3 << double1
22 << string4 << integer << string5 << &integer;
23
24 // call str to obtain string contents of the ostringstream
25 cout << "outputString contains:\n" << outputString.str();
26
27 // add additional characters and call str to output string
28 outputString << "\nmore characters added";
29 cout << "\n\nafter additional stream insertions,\n"
30 << "outputString contains:\n" << outputString.str() << endl;
31 }
outputString contains: Output of several data types to an ostringstream object: ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.