File Operations in C++:
The data files can he opened into different modes. These modes are defined in “ios” class. The resolution operator (::) is used between the “ios” and the mode code. The different file operation modes and their uses are:
ios : : out Opens file in output mode to write data into the file. If the file with same name already exists on the disk (in the same directory), all data in the file is deleted and the file is opened as a new file.
For objects of the ofstream class, its uses is optional.
ios : : app Opens file in output mode to append (add) data at the end of the tile. If the file already exists, it is opened without deleting any data in it. If the file does not exist on the disk then a new file with the specified name is created.
ios : : ate Moves the file pointer to the end of the file when the file is opened.
ios : : in Opens file in input mode to read data from the file. The data can only be read from the file and no data can he written into it.
For objects of the ifstream class, its use is optional.
ios : : trunc In this mode, the data of the file is deleted if file already exists on the disk. It is also the default setting for “out” mode.
ios : : nocreate No new file is created. If the file does not exist, the “file open” operation fails.
ios : : noreplace The tile is not replaced if it already exists with the same name on the disk, If the file with the same name exists, the open operation fails.
ios : : binary Opens the file in binary mode. In this mode data is stored and accessed in binary format.

The opening modes can be combined together to perform different combination of input/output operations on the file. These are combined with the logical OR operator ( | ).
For example, to perform both input & output operations on the file in binary mode, the statement is written as:
object.open (filename, ios::in | ios::out | ios::binary);
where:
object represents the created object of fstream class. The object of fstream can he used both for input and output operations.
comment closed