-
ofstream output
Can someone tell me whether its possible to output the contents of a float/int in the same way that fwrite does (e.g. 4 bytes in the same way that are represented in memory) when using a std:: ofstream.
Thanks
EDIT: Should've mentioned that I'm hoping to use the << operator rather than the write function, if possible.
-
The write functions are for binary io, which is what you want in this case:
Code:
float f;
ostream file;
file.write(f,sizeof(f));
Also, don't forget to open the file with the flag ios_base::binary