Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |
Manipulating files with iostreams is much easier and safer
than using stdio in C. All you do to open a file is create an object the
constructor does the work. You don t need to explicitly close a file (although
you can, using the close( ) member function) because the destructor will close it when the object goes out of scope. To create a file that defaults to input,
make an ifstream object. To create one that defaults to output, make an ofstream
object. An fstream object can do both input and output.
The file stream classes fit into the iostreams classes as
shown in the following figure:

As before, the classes you actually use are template
specializations defined by type definitions. For example, ifstream,
which processes files of char, is defined as
typedef basic_ifstream<char> ifstream;
Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |