PO> Hey I read your msg. and applied some of your code snipits to some
PO> simple little programs some worked some didn't. However I think I got
PO> the jist of what you said but I want to make sure I understand.
Which didn't work?
-> ofstream savefile("hiscore.lst");
-> savefile << player_name << ',' << player_score;
PO> ok 'ofstream savefile("hiscore.list");' creates some sortof pointer
PO> titled 'savefile' which points to a file titled "hiscore.list" ok,
NOOOOOOO! It creates an OBJECT called "savefile" which ENCAPSULATES
operations on a file called "hiscore.lst".
PO> first question is the file "hiscore.lst" created as soon as this
PO> pointer is initialize? if not then when?
It doesn't matter, it will be created before or when necessary. In general,
it is created on construction.
PO> the next line 'savefile << player_name << ',' << player_score;' calls
PO> the pointer and writes the variables 'player_name' & 'player_score' to
PO> the file "hiscore.lst" separated of course by a comma.
Mind you, the above also overwrites the file each time, meaning you'd want to
have a way (function, class) of reading all the values in (so you can sort
'em in memory with the new value), and then writing them all out...
PO> I'm not real sure why this is important to me but I just wanted to
PO> know.
There seems to be a paradigm problem here. Are you writing C or C++? The
above is (almost) C++. I say "almost" only because for "full" C++, you would
have classes encapsulating player's name, score, etc., into a class called
"Player", with a member function to save and to restore the high scores. You
would probably also have a class to help manipulate hi score files (i.e.,
finding where in the file the current hi score belongs, if anywhere). The
above starts on teaching the basics, later you can incorporate more as you
understand more.
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|