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:
1
2
3
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.
http://www.cplusplus.com/forum/beginner/11110/page1.html#msg52401

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