Save code??

I am making a text based rpg game but since its so big I need a way to make the game save all the data of the user and be able to load it when the person wishes to continue...

My problem is is that i dont know how to approach the code to make the save and load it...

can someone plz help me...
thx in advance.
Write to a file all the variables you need for the game
http://www.cplusplus.com/doc/tutorial/files.html
you have to save the state of the game when the user closes it. in windows programming term it is called serialization. i.e. writting the state of application to a text file in some format and when the application again starts it reads the state from that file.

i give you an example: lets say you have a drawing program and a user has drawn two things on the sheet. A line and a rectangle.
line has cordinates (0,0),(50,100) and the color is red.
rectangle has cordinates (101,101),(200,200) and the user exists the program.
lets say i have a data structure like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
typedef struct SHEET_INFO
{
int start_x;
int start_y;
int end_x;
int end_y;
int color;
}SI;

SI line1;
line1.start_x=0;
line1.start_y=0;
line1.end_x=50;
line1.end_y=100;
line1.color=RED;   //RED might be a defined type 


now you just have to write "line1" to the file and similarly for the rectangle. now when the user opens the file again it will read the info sequentially and draw the sheet again to continue the painting. correct???

this way you need to see what all you have in your game which should be stored, implement your data structures and save this to your data file.
i hope this info will be useful...
You need to evaluate the persistent data that you need to maintain along all the game and then save it to a file in any format that you desire, if your game is simple then just write a struct in binary mode like writetonsharma specified.
Topic archived. No new replies allowed.