+3 votes
in Class 12 by kratos

Explain any three modes to open a file in C++.

1 Answer

+6 votes
by kratos
 
Best answer

The file can be opened both for input and output operations using fstream class.
The syntax for opening a file with constructor is fstream object(“filename”, mode);
The syntax for opening a file with open() is fstream object.open(“filename”, mode);
Therefore, file can be opened using different modes. They are
ios::in opens file for reading only. For example, fstream fin(“te’xt.dat”, ios::in);
ios::out opens file for writing only. For example, fstream fout(“text.dat”, ios::out);
ios::app opens a file to append to end of file. For example, fstream
file.open(“text.dat”,ios::app);

...