I've tried following the instructions here, but I'm having some trouble loading the files. I think this may be because of the strings and vector I use in my structure, as I found a post while googling that suggested resizable (structures?) as a possible problem.
Anyways, here's the structure:
And here are the save and load functions...Code:struct _game { std::string plyr_name; std::string plyr_class; int plyr_x; int plyr_y; int plyr_health; int plyr_maxhealth; int plyr_ap; int plyr_str; int plyr_dex; int plyr_per; int plyr_end; int plyr_int; map current_map; string shortlog[6]; vector<string> longlog; vector<enemy> enemies; };
The program compiles fine, but when I try to load a game it breaks ("Your Program has encountered a problem and needs to close")... saving seems to work fine, but I'm thinking the problem is with the syntax somewhere in there, as I have no idea how most of the stuff in the read and write functions works...Code:void save_game(_game Game) { ofstream savefile("save.dat", ios::out | ios::binary); savefile.write(reinterpret_cast<char *>(&Game),sizeof(_game)); savefile.close(); } void load_game() { _game loadgame; ifstream loadfile("save.dat", ios::in | ios::binary); loadfile.read(reinterpret_cast<char *>(&loadgame),sizeof(_game)); loadfile.close(); }
That being said, even when I do get a game loaded, how would I go about copying the information from the loaded structure to a pre-existing one used to play?
Thank you for your time, sorry if this comes across as immature, but I'm tired, and have things I need to do before I go to sleep.
Timothy



LinkBack URL
About LinkBacks


