Advertisement Jump to content
Sign in to follow this  

Saving and Loading in a Text based game.

This topic is 3862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I go about saving and loading the players stats into some sort of file, and retrieve them at a later point if they wish to continue with that character. Something like this?
#include <iostream>
#include <fstream>
#include <string>

int main()
std::string PlayerName = "HEro";
std::ofstream Save("Player.txt", std::ios::app);
Save << PlayerName; << std::endl;
return 0;

Maybe? If that works how would I retrieve the data.

Share this post

Link to post
Share on other sites
That is fine.

Using ifstream (also part of the fstream header), you open the file just like with ofstream, and stream like if you were using std::cin.


Share this post

Link to post
Share on other sites
The general term for this process is serialization, and much more informative information on it can be found here, along with google. The former should give you more than enough to look at for a while, even when you need to save fancy game states, like inventories, multiple characters, and the like.

If you have any more particular questions, let 'em rip!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!