For performing file IO in C++ we use the ofstream, ifstream and fstream classes.
Because the mode is not limited to input/output. The constructor of ifstream
, for example, looks like:
explicit ifstream ( const char * filename, ios_base::openmode mode = ios_base::in );
Note the default value is ios_base::in
, so you don't have to specify it yourself. However, the mode
sets the streams flags which are not limited to in
/out
, but include:
app
(append) Set the stream's position indicator to the end of the stream before each output operation.ate
(at end) Set the stream's position indicator to the end of the stream on opening.binary
(binary) Consider stream as binary rather than text.in
(input) Allow input operations on the stream.out
(output) Allow output operations on the stream.trunc
(truncate) Any current content is discarded, assuming a length of zero on opening.