Saving data

So I just finished my first class in C++ and I have really enjoyed programming. I have begun to create programs of my own, but I feel that there is one aspect that is severely limiting my options. What are some methods of saving data so that you can start where you left off the next time you run the program.

The first thought that I had was saving everything to a file, but I don't know how practical that would be.

If there are any other methods, or if that is a viable method, I would love to know.

At the core, file I/O is handled using the fstream library. http://www.cplusplus.com/reference/fstream/fstream/

You'd have to ensure you saved the data in the format you wanted in and write functionality that would read it back in correctly.

There are myriad ways to store data. I believe that using xml is quite common too. Though fstream is about as basic and simple as it gets.
Your first thought was correct, but there are several ways to do that. Let's take a configuration file for example. Usually you see something like
option1 = "value1"
but you could also do
1
2
3
value1
value2
value3
.
In the first case you read the option and assign the value to the associated variable, in the second case you will read them in sequence and will need to assign them in that order without the ability to use a default value if an option isn't specified (because you can't know which one is missing).

Anyway, yeah, files.
Topic archived. No new replies allowed.