fstream myFile("test.txt", ios::in | ios::out | ios::trunc);
How is this line interpreted by the compiler in C++ file handling?
ios::out means that you intend to write to the file in contrast to reading ios::in. In your case the stream can be used for both reading and writing.
ios::out
ios::in
ios::trunc means that the current file content will be discarded. Compare this to ios::app where you will append to a file if it exists. ios::trunc is implied if not ios::in is specified for example. "When used for an ofstream without ios::app, ios::ate or ios::in, ios::trunc is implied."
ios::trunc
ios::app
Bonus:
iso::binary means that what you will write will be put verbatim into the file (otherwise for windows could be replaced with for example)
iso::binary
1.4m articles
1.4m replys
5 comments
57.0k users