Chapter 8 The IO Library
The IO Classes
- IO library types and headers (
wchar_tversions begin with aw):

- IO type objects cannot be copied or assigned.
- Reading or writing an IO object changes its state.
- IO library condition states and ways to interrogate the state of flags:
iostatevalues are sets of bit flags representing different errors.

- Conditions that cause the buffer to be flushed:
- The program completes normally (returns from
main). Buffers are not flushed if the program crashes. - The buffer becomes full.
- The buffer is flushed explicitly (
endl: adds a newline,flush: no new data,ends: adds a null, etc.). unitbufis used to set the internal state to empty the buffer after each output:cout << unitbuf / nounitbuf.unitbufis set forcerrby default.- If it is tied to another stream (
cin,cerrare tied tocout), reading or writing on other streams will flush the tied output stream. Streams has two overloadedtiemember functions:tie()returns the stream it’s tied to, andtie(s)ties itself tos.
- The program completes normally (returns from
File Input and Output
- Operations specific to
fstream:

ifstreamandofstreaminherit fromistreamandostream.- If a call to
openfails,failbitis set, and we can useif (out)to check if it succeeded. fstreamobjects are automatically closed if out of scope.- File Modes (preceded with a scope
ofstream::/ifstream::):- Default mode for
ofstreamisoutandtrunc.
- Default mode for

string Streams
- Operations specific to
stringstreamfor quick input and output:

PersonInfo info; // create an object to hold this record's data
istringstream record(line); // bind record to the line we just read
record >> info.name; // read the name
while (record >> word) // read the phone numbers and store them
info.phones.push_back(word);