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 ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Third Edition 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.