Chapter 8. The IO Library
Contents
- Section 8.1 The IO Classes
- Section 8.2 File Input and Output
- Section 8.3
string
Streams - Chapter Summary
- Defined Terms
The C++ language does not deal directly with input and output. Instead, IO is handled by a family of types defined in the standard library. These types support IO to and from devices such as files and console windows. Additional types allow in-memory IO to and from string
s.
The IO library defines operations to read and write values of the built-in types. In addition, classes, such as string
, typically define similar IO operations to work on objects of their class type as well.
This chapter introduces the fundamentals of the IO library. Later chapters will cover additional capabilities: Chapter 14 will look at how we can write our own input and output operators, and Chapter 17 will cover how to control formatting and how to perform random access on files.
Our programs have already used many IO library facilities. Indeed, we introduced most of these facilities in § 1.2 (p. 5):
istream
(input stream) type, which provides input operationsostream
(output stream) type, which provides output operationscin
, anistream
object that reads the standard inputcout
, anostream
object that writes to the standard outputcerr
, anostream
object, typically used for program error messages, that writes to the standard error- The
>>
operator, which is used to read input from anistream
object - The
<<
operator, which is used to write output to anostream
object - The
getline
function (§ 3.2.2, p. 87), which reads a line of input from a givenistream
into a givenstring