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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.