Sunday, 13 November 2016

Modes of File in C++

Modes of File
we can open a file multiple modes with a combination of the following flags:
Open for input operations.
Open for output operations.
Open in binary mode.
Set the initial position at the end of the file.
If this flag is not set to any value, the initial position is the beginning of the file.
All output operations are performed at the end of the file, appending the content to the current content of the file. This flag can only be used in streams open for output-only operations.
If the file opened for output operations already existed before, its previous content is deleted and replaced by the new one.
All these flags can be combined using the bitwise operator OR (|). For example, if we want to open the file example.bin in binary mode to add data we could do it by the following call to member function open():

        ofstream myfile; ("example.bin", ios::out | ios::app | ios::binary);          

No comments:

Post a Comment