File Stream Classes with iostream Classes
- Its purpose is to set the file buffers to read and write.
- Contains Openprot constant used in the open() of file stream classes. Also contain close() and open() as members.
- Provides operations common to the file streams serve as a base for fstream, ifstream, and ofstream classes.
- Contains open() and close() functions.
- Provides input operations. Contains open() with default input mode. Inherits the functions get(), getline(), read(), seekg() and tellg() functions from istream.
- Provides output operations. Contains open() with default output mode. Inherits put(), seekg(), tellp(), And write(), functions from ostream.
- Provides support for simulations input and output operations. Contains open() with default input mode. Inherits all the functions from istream and ostream classes through iostream.
File Mode Parameters
- Opening a file in ios:: out mode also opens it in the ios:: trunc mode by default.
- Both ios:: app and ios:: ate take us to the end of the file when it opened. The difference between the two parameters is that the ios:: app allows us to add data to the end of file only, while ios:: ate mode permits us to add data or modify the existing data anywhere in the file. In both the cases, a file is created by the specified name, if it does not exist.
- Creating a stream using ifstream implies input and creating a stream using ofstream implies output. So, in these cases, it is not necessary to provide the mode parameters.
- The mode can combine two or more parameters using the bitwise OR operator shown as follows.
- Fout.open(“data”, ios:: app | ios:: nocreate);
- This opens the file in the append mode but fails to open the file if it does not exist.