File I/O in C++ - The Basics

You should already be familiar with using the "insertion" or "put to" operator >> to send output to cout. The object named cout is member of the class ostream, or output stream.

Likewise, you should already be familiar with using the "extraction" or "get from" operator << to read input from cin. The object named cin is member of the class istream, or input stream.

The class definitions for these streams are defined in the header file iostream.h, which must be included in each program that gets input from cin or writes output to cout or cerr (the standard error, usually the terminal too).

In the exercises that follow, keep in mind that an object (like cout) that is declared to be one of the stream types is really variables of a particular type (or class). Thus member functions can be invoked on that stream object, and operators can be applied to it. (Just like a string object can have a length() operator invoked on it, or could be concatenated with the "+" operator.)

If you're not clear about these basics, you may want to review some of the textbooks you have on these topics. See, for example, Session 2 and also page 222 in the C++ Laboratory Manual.

There are no exercises for this sections. You've already programmed with the basics, after all!


Now use your browser's "back" button to go back to the list of topics so you can do the remaining exercises.


Last modified on 06/26/2005.