Next: Review Questions
Up: Streams and External Files
Previous: Testing for end-of-file
- To send data to/from an external file the file must be connected to a
stream.
- A stream is a sequence of characters and is connected to a device or a
file.
- If streams other than the standard input streams
cin and
cout are used then the file fstream.h must be included
in the program.
- Streams must be declared. Input streams are declared as having type
ifstream and output streams as having type ofstream.
- A file is connected to a stream using the
open(filename) member function of the stream.
Failure of the
open(filename) function is tested by the
fail() member function of the stream. End of file condition is
tested by the eof() member function of the stream. A stream
(and the associated file) is closed by using the close()
member function of the stream.
Next: Review Questions
Up: Streams and External Files
Previous: Testing for end-of-file
Peter JB King
1999-08-31