Sign in to follow this  

C++ io fstream

This topic is 4071 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
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

This topic is 4071 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this