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:
ios::in
Open for input operations.
ios::out
Open for output operations.
ios::binary
Open in binary mode.
ios::ate
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.
ios::app
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.
ios::trunc
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;
        myfile.open ("example.bin", ios::out | ios::app | ios::binary);          
 

No comments:

Post a Comment