1: //output_string_stream.cpp
3: #include <iostream>
4: #include <sstream>
5: using namespace std;
7: int main()
8: {
9: cout << "\nThis program illustrates an output string stream.";
10: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
12: cout << "\nFirst we create an output string stream object in memory."
13: "\nThen we write some values to that object (again, in memory)."
14: "\nThen we output the contents of the string stream object to "
15: "the standard output.";
16: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
18: //Create a string containing the command-line expression
19: ostringstream outputString;
20: outputString << 123 << " ";
21: outputString << 3.14 << " ";
22: outputString << 'A' << " ";
23: outputString << "Hello, world!";
25: cout << endl;
26: cout << outputString.str();
27: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
28: }