TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: PHIL OHL
from: DARIN MCBRIDE
date: 1998-03-06 18:33:00
subject: Writing to a file

 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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.