If you want to continue reading and writing files, you must first complete the first step of opening. Then how to open the file in C++? Here you need to use the member function open() in the fstream class to implement the operation of opening the file. The open function is a member function of istream, ostream, and fstream. Its prototype is as follows:
voidopen(constchar*filename,ios::openmodemode);
The first parameter filename represents the path of the file to be opened.
The second parameter mode represents the mode for opening the file.
In addition, you can also use ' | ' or operator to use multiple parameters, such as:
1ofstreamout;2out.open(dotcpp.txt,ios::out|ios::binary)//Open in binary mode to write data
You can test it on your own computer.