Is there a way to save in a text based game through the MSDOS window? I want to be able to save the variables that store the mana, health, ect of a player.
Shadoninja
0
Light Poster
Recommended Answers
Jump to PostSure.
All you need to decide is which variables you have in your game which are necessary to restore the state of the game.
Jump to PostYou would use ifstream to read data (much like cin), and ofstream to write it (like cout). (note: cout and cin are objects of classes that are already made. ifstream and ofstream are actual classes).
To write data:
ofstream fout("file.sav"); fout << health << "\n" << …
Jump to Postor make one class game_state and then output.write(&game_state, sizeof(game_state)) and to restore input.read(&game_state, sizeof(game_state))
All 11 Replies
Salem
5,138
Posting Sage
CoolGamer48
65
Posting Pro in Training
ivailosp
11
Junior Poster
Shadoninja
0
Light Poster
Salem
5,138
Posting Sage
Shadoninja
0
Light Poster
CoolGamer48
65
Posting Pro in Training
Shadoninja
0
Light Poster
kidprogrammer
0
Newbie Poster
Shadoninja
0
Light Poster
kidprogrammer
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.