|
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);
|