9

Input and Output Streams

Science is what we have learned about how to keep from fooling ourselves.

– Richard P. Feynman

In this chapter, we present the C++ standard-library facilities for handling input and output from a variety of sources: I/O streams. We show how to read and write files, how to deal with errors, how to deal with formatted input, and how to provide and use I/O operators for user-defined types. This chapter focuses on the basic model: how to read and write individual values, and how to open, read, and write whole files.

§9.1 Input and output

§9.2 The I/O stream model

§9.3 Files

Opening a file; Reading and writing a file

§9.4 I/O error handling

§9.5 Reading a single value

Breaking the problem into manageable parts; Separating ...

Get Programming: Principles and Practice Using C++, 3rd 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.