Archived

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

File I/O for multiple classes

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have more then one class with game data in my program (i.e. player, map changes, combat units). Now I want to save them in a single file. I am not always going to know exactly how many of each I will have (i.e. sometimes 10 combat units, sometimes 20, sometimes 2 players, sometimes 4). How is the best way to handle something like this? Should I write some kind of header for each of the different types so I can tell how many will follow (i.e. 2 player player 1 mapchange 3 unit unit unit)? or is there a better way? I am using binary streams to save the objects. All that is gold does not glitter, Not all those who wander are lost; The old that is strong does not wither, Deep roots are not reached by frost. [edited by - alchemar on July 25, 2002 7:31:31 PM]

Share this post


Link to post
Share on other sites
Prefixing the list with the number of items to expect is a good and well-used method. Use it if you want.

Another way is to use some sort of ''delimiter'' - a unique word or character that marks the end of a block. Reading a list becomes a case of checking for the delimiter, and if you don''t have it, read another object, then check again... repeat until you hit the delimiter.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

Share this post


Link to post
Share on other sites