Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, I'm looking for a way to save class data for a game I'm developing and need to save it as a binary file for a savegame and a text file for user settings.
I did find an article on Google about saving binary files but couldn't find it again,
Thanks in advance for the answers.
Posted
Updated 6-Oct-10 2:12am
v2
Comments
ryan20fun 6-Oct-10 7:47am    
Sorry if there arnt enough tags but I couldent
Get other tags to work like class data storage,
It was the only one it accepted

Why not just save it as XML? Here's an article that will help you save/load a simple xml data file:

XML Application Profile Class[^]
 
Share this answer
 
If you want to save anything then streams are the answer - implement:

std::ostream &operator<<( std::ostream &, const object & );

and:

std::istream &operator>>( std::istream &, const object & );

for your class and snip, snip, Bob's yer Aunty.

How difficult this will be depends on how you've structured your data.

Cheers,

Ash
 
Share this answer
 
Comments
Dalek Dave 7-Oct-10 3:38am    
Good Call.
I suggest this series of article: A serialization primer - Part 1[^]. Of course, this is related to MFC but at least you can learn some interesting things and adapt those to your own case.
As John already suggested, I would use XML to save the user settings. But only for the settings, the data of your game should be saved as binary file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900