ios::binary.... a discussion (mostly)
Code:
#include <fstream>
using namespace std;
int main()
{
ofstream outs;
outs.open("file.dat", ios::binary);
outs << "ABCD" << "\n\n\n";
outs.write("1234",4);
outs.close();
return 0;
}
ok... so we have a handly little binary file named file.dat that when opened with notepad contains...
ABCD###1234
(count the #s as small black squares)
What is the purpose of this? I skipped the whole binary process in file I/O because it didn't interest me at the time... now it does.
Over the past couple of years, we have had a lot of questions regarding binary files. For some reason, all this time, I was led to believe that binary files were not human readable. (Couldn't have been more off the mark with that thought...)
What the heck do you use a binary file for that a ascii file cannot do?
As naive as it may sound... I actually thought when I opened the file I would see a bunch of ones and zeros... you know... binary.... LOL.
:)