Jump to content
  • Advertisement


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


Binary File Output?

This topic is 6478 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 there, can anybody help me with writing some data into a binary file? here is the code i use:
        ofstream File;
	int StartPos[3];

	File.open("map.dat",ios::out | ios::binary);

	File.write((char*)StartPos, sizeof(StartPos));
	File.write((char*)x, sizeof(x));
	File.write((char*)y, sizeof(y));
	File.write((char*)map, sizeof(map));
	File.write((char*)StartPos, sizeof(StartPos));
without the x and y datas it works, but with them, there is an error in the function ''streambuf::xsputn''. Hope you can help me.

Share this post

Link to post
Share on other sites
While I''m not familiar with the C++ File IO methods, I suspect your problem is that it expects a pointer, you can''t cast a non-pointer into a pointer like you have:

(char *)x

you would have to go:

(char *)&x

but in those function calls, you could probably get away with:


as the parameter.


Share this post

Link to post
Share on other sites
Ok I think that works, there is no error. but when i try to read the file, it reads the wrong data ...
do you know another method to write and read binary data?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!