PO> Say I created a game and I prompted the user for
PO> his/her name to be placed on the high score list. How could I place
PO> the name in a seprate file so it can be retrieved the next time the
PO> game is played and the high scores displayed.
Hmmm... look at the fstream classes. i.e.:
ofstream savefile("hiscore.lst");
savefile << player_name << ',' << player_score;
Note that if you are going to read it in, you will have to deal with spaces
by hand...
ifstream savefile("hiscore.lst");
char buf[255];
savefile.getline(buf,255);
// manually parse the line - if you use the above, look for a comma -
// everything before the comma is the name, everything after is the score.
Actually, in this case, we can "cheat" a bit:
ifstream savefile("hiscore.lst");
char buf[255];
savefile.getline(buf,255,',');
player_name = buf;
savefile.ignore(1); // rid of comma - I can't recall off hand if this is
// needed or not...
savefile >> score; // read & convert the high score
Please look these functions (including the operators) up in your manuals for
further info. If you have more questions, please come back and ask.
Hope this helps,
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|