views:

522

answers:

5

How to save c++ object into a xml file and restore back?

+3  A: 

This might help

http://www.codeproject.com/KB/cpp/xmlserialization.aspx

rangalo
+1 - voodoo :)
Aiden Bell
A: 

I don't know if any direct way of achieving this. You can write separate methods to serialize and de-seriealize methods in which individual data members of the object need to be written and extracted from the file.

aJ
+7  A: 

Boost's serialization library might be implementing a lot of the functionality you are looking for.

Oliver N.
+5  A: 

Serialization is a complex topic which is probably too much for a simple answer on SO. Unfortunately with C++, you don't get it for free as in other languages.

See the C++ faq lite or boost for a start.

Tobias
+10  A: 

Boost.Serialization and libs11n can both do this. The libs11n manual (available here) has an extensive comparison of the two.

As Tobias said, the C++ FAQ has good background information.

Josh Kelley