if i opened a file like:
ofstream file("file.dat",ios::binary);
or
ofstream file("file.dat",ios::binary | ios::out);
what can i do with a file opened in the latter form that i can't do with the former form and vice versa
thank you
ios::binary makes sure the data is read or written without translating new line characters to and from \r\n on the fly. In other words, exactly what you give the stream is exactly what's written.
8. Which of the following is the default mode of the opening using the ofstream class? Explanation: By default, the file is opened in ios::out mode if the file object we are using is of ofstream class. 9.
For an ofstream, ios::out
is the default, so there's no difference. I believe the only time specifying ios::out makes a difference is if you use an fstream, which can be opened for reading or writing, or both.
In most cases I would expect there to be no difference, though it seems like this could technically be implementation specific.
In my implementation (gcc 3.4.3) the open for the ofstream uses the ios:::out mode in the ofstream->open() call regardless of what is specified via the constructor so it's purely optional. If using fstream, this is not the case and would need to be specified explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With