Saving Class Data to a file

Started by
3 comments, last by Zahlman 18 years, 5 months ago
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
What we do in life... Echoes in eternity
Advertisement
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).
“Always programm as if the person who will be maintaining your program is a violent psychopath that knows where you live”
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.
Rob Loach [Website] [Projects] [Contact]
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.
What we do in life... Echoes in eternity
Read. Learn.

This topic is closed to new replies.

Advertisement