• Advertisement
Sign in to follow this  

C++ io fstream

This topic is 4143 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I am writing a function to save a bitmap, and i am having a problem with file io I have simple code: std::ofstream OutBin("test.bin", std::ios_base::binary | std::ios_base::out); OutBin << 0xDEADBEEF; But right now that writes a 10 byte long file with contents "3735928559". I would like to know how I can get it to write a 4 byte long file with hex DEADBEEF.

Share this post


Link to post
Share on other sites
Advertisement
operator << and operator >> (for istream) works with text output/input. That is, your data will be converted to/from text.
If you want to write/read bytes to/from stream (note - any stream, not only file stream), then you must use the stream methods write/read.
Just look up for those methods in your compilers help files.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement