Save Data Help

Not open for further replies.


In Runtime
I am currently programming a text based game, and I want to save stats like health, gold, etc to a data file, which I know how to do, but, how do I make sure that the health always saves to line one and the gold to line two etc, because if it's not saved that way the input will end up reading the wrong thing, and say if they have 1 gold and 50 health, if it saves in a line, it may read 1 health, 50 gold, etc.
you'll need to use seekg and possibly tellg to position the file pointers
Ok rather than use seekg you could use a struct to store the game info as followes


struct Info
int a,b,c;
char name[20];

void main()

Info info = {10,20,30,"jones"};

ofstream tfile( "c:\\myfile.txt" , ios::binary );
tfile.write( (char *) &info, sizeof info );

ifstream tIn("C:\\myfile.txt");*)&info,sizeof info);
cout<<info.a<<" "<<info.b<<" "<<<<endl;
Not open for further replies.
Top Bottom