Question:
How can I archive the values stored in variables? (C++)?
anonymous
2008-10-24 21:08:28 UTC
I am trying to make a game with a feature for people to exit, and then pick up where they left off at a later date. I am wondering how i would go about archiving the values currently stored in variables, and how i could import and reassign them when the program was restarted. (Obviously so that C++ does not just reset the variables. I am essentially trying to find a way to keep the values of my variables.)
Three answers:
nita
2008-10-24 21:16:01 UTC
You have to use File Handling in C++. Search in net for file handling in C++ & obviously you will get ur way.
P34C3
2008-10-24 21:50:49 UTC
If you are using objects, you have to find a way to serialize and de-serialize it, perhaps to a file. If you are not using objects, you can write the values in a save() function to a file when people exit. You can then have a load() function that picks up from where people left off when they resume.

Make sure that you handle conditions like having a unique file for every user or a unique way to set the properties in the same file for every user. You may also want to think of a way to handle the situation if a program/game crashes in the middle.
?
2008-10-24 21:14:14 UTC
You could write them to a text file, then make it read upon opening


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...