Quote:Original post by Denisb
Thanks all but. How do i make it load the game :O
This is how you could do it.
This is the struct that will be used to hold the game info for the save and the load functions:
struct status{ string name; int gold; int TP; // Time played};
Then I made a function (in my game it's a class function, so you'll have to implement it the way you want) called Game::gSave():
void Game::gSave(){ status game; // class of type status, look up game.name = hName; game.gold = gGold; game.TP = gTP; ofstream save("game.sav", ios::out | ios::binary); if (!save) { cout << "\nCan't open the file for saving!\n"; } else { save.write((char *) &game, sizeof(status)); cout << "\nGame saved!\n"; save.close(); }}
And here comes the the source for loading the game:
void Game::gLoad(){ status game; ifstream load("game.sav", ios::in | ios::binary); if (!load) { cout << "\nCan't open the file for loading!\n"; } else { load.read((char *) &game, sizeof(status)); hName = game.name; gGold = game.gold; gTP = game.TP; cout << "\nThe following game stats are loaded:\n"; cout << "Name: " << hName << "\n"; cout << "Gold: " << gGold << "\n"; cout << "Time played: " << gTP << "\n"; load.close(); }}
If you got any questions, just ask :-D