October 16th, 2013, 11:42 PM
Save/load functions not working
Hi. I've been working on a battle simulator, and using it as a learning experience. So far, I've been able to debug the program(with some help), and learn some stuff, and it's been running smoothly. It's still runnable, but I've been trying to make it so the player can save his character, and continue the game later. However, I'm not sure whether it's the save or load function that's not working, because even if i save to a txt file, it's just a bunch of random characters. I don't know if that means it's not saving correctly, or if it's just supposed to be like that. Anyway, here are the two functions I'm speaking of:
Can anyone identify the problem from this? My program is in multiple files, so I can't really post the whole code easily, but I can upload or something if I really need to.
void Game::saveGame(Character &player)
std::ofstream saveFile("save.bin", ios::binary);
saveFile.write((char *)&player, sizeof(player));
std::ifstream loadFile("save.bin", std::ios::binary);
loadFile.read((char *)&player, sizeof(player));
loadFile.close();// needs player info
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!