C ++ how to serialize / deserialize an object?

Possible duplicate:
How to save a C ++ object in an xml file and restore it back?

Hi,

Can someone tell me what is the best way to serialize and deserialize (of course) an object? I have a class with a lot of strings, int values. What is the western way to create XML and after that (when I have xml) to open it and get the values?
Can you give me some code examples?

+3
source share
2 answers

To serialize / deserialize an object, you only need to do this:

ofstream f( "output.bin", ios::binary );

f.write( (char *) &myObject, sizeof( myObject ) );
f.close();

// later...

ifstream f( "output.bin", ios::binary );
MyClass myObject;
f.read( (char *) &myObject, sizeof( myObject ) );
f.close();

. , , . , , .. .

, . , XML. XML-, Xerces.

, toXML() , , [] fromXML() XML.

, Xerces .

, .

XML, Xerces ( XML), , . , .

+4

All Articles