Best way to get/store data from a file?
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?
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:
where theFile has been declared as an fstream object, and of course MonsterType is your monster struct/class.
hope this helps.
boto0o
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
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement