File operations in C++ are mainly supported by the following classes, which are:
ofstream : file class for write operations (output) (derived from ostream)
ifstream : File class for read operations (input) (derived from istream)
fstream : A file class that can read and write at the same time (derived from iostream)
They all need to include header files :
#include<fstream>
Still like the C language, there are three steps to reading and writing files, namely:
1. Open the file
2. Read and write files
3. Close the file
The difference is that the functions used to read and write files in C++ are all methods in the above three classes, which fully embody the object-oriented design idea. We will explain each step separately later.