fstream binary mode

Hi everyone,

So I've been setting an fstream class with openmode as binary and reading info to it, as in the following example:
fstream file("foo.txt",ios_base::out|ios_base::binary);
int i = 1024;
file << i;

Now I would've expected to see, in foo.txt, the binary representation of 1024. But I keep getting the text of '1024'. Am I wrong in one of my assumptions, or am I just doing something wrong? Thanks in advance!
Yes, your assumptions are wrong. The << and >> operators are for formatted I/O. If you just want to handle raw data (binary data), you must not use them.

Here are a couple functions I posted just recently for doing just what you want.

Hope this helps.
Ah, great. Thank you!
Topic archived. No new replies allowed.