8.2. File Input and Output
The fstream
header defines three types to support file IO: ifstream
to read from a given file, ofstream
to write to a given file, and fstream
, which reads and writes a given file. In § 17.5.3 (p. 763) we’ll describe how to use the same file for both input and output.
These types provide the same operations as those we have previously used on the objects cin
and cout
. In particular, we can use the IO operators (<<
and >>)
to read and write files, we can use getline
(§ 3.2.2, p. 87) to read an ifstream
, and the material covered in § 8.1 (p. 310) applies to these types.
In addition to the behavior that they inherit ...
Get C++ Primer, Fifth 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.