Archived

This topic is now archived and is closed to further replies.

HydroX

Best way to get/store data from a file?

Recommended Posts

HydroX    122
I am a currentlly some sort of newbie in c++. I am up to the part in my engine were i need to get a mosters name... like its Name, Damage, Defense e.t.c I know how to use ifsteam/ofstream, but i need a idea how to store them and best way to recall them Like storing as Name|str|mon . any comments?

Share this post


Link to post
Share on other sites
bot_o0o    122
you can store them any way you want, but it''s a little easier to store them seperated by line breaks. for example:

monstername
monsterdamage
monsterdefense

monstername2
monsterdamage2
monsterdefense2

then you can just read them with something like this:


MonsterType monster[NUM_MONSTERS];
int x = 0;

while(!theFile.eof())
{
theFile >> monster[x].name;
theFile >> monster[x].damage;
theFile >> monster[x].defense;
++x;
}


where theFile has been declared as an fstream object, and of course MonsterType is your monster struct/class.

hope this helps.

boto0o

Share this post


Link to post
Share on other sites
Lanman    122
I don''t know exactly what do you mean but I would create a file where the monster are saved and then when I need it i simply load the data into the memory to some kind of structure.

Share this post


Link to post
Share on other sites