Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Binary output ofstream/VC++ WTF?!?!

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

char c[4] = {2,0x0A,0xFF,0x0D}; ofstream o; o.open("test"); o.write(c, 4); o.close(); // first five bytes of test: 02, 0D, 0A, FF, 0D ofstream inserts 0x0D before 0x0A! I tried a few other cases too. This is banal! I figure it''s because 0A is Line-Feed, and 0D is carriage return, and for some reason M$ expects that I''m trying to create a file for reading. anyone know of a workaround? or maybe a flag I''m not setting right? George D. Filiotis I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Programmer16
ofstream o("test.txt", ios::binary);


Do you have to give the other flags with it? Like ios::out and ios::trunc? Or are they assumed by the ofstream class?

Share this post


Link to post
Share on other sites
With ofstream, ios::out is assumed. And with ifstream, ios::in is assumed. If you want to use ios::trunc you do have to apply it too.
Example:
ofstream o("test.txt", ios::binary | ios::trunc);

/*
I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)
*/

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!