Jump to content
  • Advertisement

Archived

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

QBRADQ

Help with ofstream file output.

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

//Sorry if this is duplicate I am having trouble with ofstream file output, well, I think I am anyway. I am trying to print a DWORD to it (32-bit interger), but when I open it in notepad I see only one character where the DWORD should be. IDEA: Checking it with EDIT under DOS-mode... Nope, shows the same thing. Anyhoo, I am openning the file in with ios::binary | ios::out. I am printting to the file such as this: ofsMapOut -- EditMap[x][y].dwEventValue; (replace the dashes with "less than" signs) (dwEventValue is indeed a DWORD) Now, are Notepad and EDIT doing formatting on the DWORD or do I need to do something else to print the value to the file?

Share this post


Link to post
Share on other sites
Advertisement
I see my problem... even though I am opening it in binary mode, it is STILL making formatted output... When I output an int (2 characters long) instead of, say µ*, instead I get 12574... WHY!?!?!?!?!??!?!? How do I change this?

Share this post


Link to post
Share on other sites
C++ iostreams don''t quite work the way you think. The ios::binary flag doesn''t make everything you send to the stream go in binary. It just stops the stream performing text conversions (which as far as I know, are limited to "\n" in memory becoming "\r\n" in a file, and vice versa). You will still need this flag set, but you don''t use the streams in that way. The insertion and extraction operators, << and >>, always write formatted (text) output. Instead, look up the ''read'' and ''write'' member functions for your needs: they function very similarly to fread and fwrite in C.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!