About fstream and also the use of stupid pointers grrr
Posted: Wed Apr 07, 2010 4:59 pm
First of all I have just been following some tutorials on pointers and I still aint got my head round them but think I have the basic idea. Also I have been reading up on reading from files, which seems pretty straight forward.
Anyway the purpose of this thread is I have an idea for the next part of my random game. By the way this game is following no structure, Im just following tutorials then writing code that I want to implement into my game, I will fill in the gaps later, Im just doing what I can.
Anyway the next thing I a want to create is a way of loading some items and some monsters, plus info about the player into the game. I am planning on doing this using an array of structures(if that is possible). I have been messing around with a way of laying out the info I need in a file and so far the only way I can think of doing this is by having a seperate file for Monsters, Items and Player. DOes this sound about right, it just seems very complex having just one file holding a lot of different information.
Im then going to have my array of structures. However when I load the files, it will be in a seperate function(probably just one file handling class specific to game later on). However this is the bit where I am having difficulty, do I declare my structures as global and just load info into them, or do I pass them onto my functions a pointer to them? If it is possible to use pointers like this, which is how I see them as being used it would be a lot simpler. Or I could load them into a structure, pass the structure to main then copy the structure to the structures already set up, which just seems a waste.
So am I right in how I am planning on using pointers. I just aint sure becasue even when I did C++ at Uni years ago, I genrally avoided pointers like the plague.
Hope my question makes sense. Or am I just barking up the wrong tree. Cheers.
Anyway the purpose of this thread is I have an idea for the next part of my random game. By the way this game is following no structure, Im just following tutorials then writing code that I want to implement into my game, I will fill in the gaps later, Im just doing what I can.
Anyway the next thing I a want to create is a way of loading some items and some monsters, plus info about the player into the game. I am planning on doing this using an array of structures(if that is possible). I have been messing around with a way of laying out the info I need in a file and so far the only way I can think of doing this is by having a seperate file for Monsters, Items and Player. DOes this sound about right, it just seems very complex having just one file holding a lot of different information.
Im then going to have my array of structures. However when I load the files, it will be in a seperate function(probably just one file handling class specific to game later on). However this is the bit where I am having difficulty, do I declare my structures as global and just load info into them, or do I pass them onto my functions a pointer to them? If it is possible to use pointers like this, which is how I see them as being used it would be a lot simpler. Or I could load them into a structure, pass the structure to main then copy the structure to the structures already set up, which just seems a waste.
So am I right in how I am planning on using pointers. I just aint sure becasue even when I did C++ at Uni years ago, I genrally avoided pointers like the plague.
Hope my question makes sense. Or am I just barking up the wrong tree. Cheers.