1 2 3 4 5 6 7 8 9

*

When an ifstream file object is created it automatically assumes that the
file will be opened for input. The first parameter to its constructor is the
name of the file
When an ofstream file object is created it automatically assumes that the
file will be opened for output. The first parameter to its constructor is the
name of the file
The destructors for both of these objects will close their files, or you can
explicitly close the file by calling the close() function on the object
The constructors for these classes can take a second parameter that
specifies how the file is opened. The values for these flags are specified in
the ios class
some of the possible values are:
-
in- open for reading
-
out- open for writing
-
ate- open and seek to end of file
-
app- append
-
trunc- truncate file to zero length
-
nocreate- fail if file does not exist
-
noreplace- fail if the file exists

If we wanted to open a file for both reading and writing we can execute:

fstream index("database.index", ios :: in | ios :: out);

*

*

*

*

*

23 March, 1998

Page 8