G. I/O Stream Objects and Classes
The objects and classes in this appendix support reading and writing to the console, as well as to files and strings. To read and write to the console, include <iostream>:
#include <iostream>cout << "Hello, world." << endl;
To write data to a string, include <sstream>. String streams support a member function (in addition to the ones listed here), str, which returns the data in string format.
#include <sstream>stringstream s_out;s_out << "The value of i answer is " << i << endl;string s = s_out.str()
Console Stream Objects
The objects listed in Table G.1 provide predeclared streams to which to read or write text to the console. Each of them supports the appropriate stream operator (<< or >>). For example: