How To Store A Variable in Memory When Program Closes

How do you store a variable in memory so that it isn't changed when the program closes? I don't have any experience with this and am just wondering how it is possible. I am creating a program and want it to store your preferences and scores. In a simple program, everything is just reset and I don't want this for my program. How do I store a variable so that it stays the same, but can be changed even when the program is turned off?
Write it into some kind of persistent storage (say a file) on program exit, and read it back on program start up.

To be able to change it from outside the program, write it as plain text.
Use data files to store any data. Take a look here:

http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.