Saving Class Data to a file
Hey,
Wasn't exactly sure what term to search for when researching how to do this but:
I've created a class for each person in say a team and inputted all their data etc, so now I want to save the "state" I suppose of each person in the same text file such as "Team1.txt" sort of thing. That being said then I want to be able to load the data back up and reinitialize a each class. I haven't a clue where to start with converting the data or anything so if someone could point me in the right direction or some buzzwords etc it would be very much appreciated. I'm using C++ on Windows, thanks again everyone.
Jemburula
Hi,
you should look into std::streams.
Or use a library that does the file stuff for you, like a xml livrary (e.g. tinyxml).
you should look into std::streams.
Or use a library that does the file stuff for you, like a xml livrary (e.g. tinyxml).
Serialization is a very nice way of saving binary data to files. Could be exactly what you're looking for. If you're looking for a more organized way of presenting it in the text file, I'd suggest looking into either XML files or a variation of config files.
Ah thank you both very much, I followed your link on serialization Rob and just whipped up a quick test and it worked like a charm. I would of tried tinyxml because I've heard of it quite alot, but I'm pretty new to using all new libraries etc so perhaps another time. Thanks again both of you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement