SourcePro : XML Streams Module User’s Guide : Enhanced Streams : Example : Serializing the book Object to a File
Serializing the book Object to a File
First create a book object and serialize it out to a file. Because the XML format generated by XML streams is difficult to read, transform the output stream to a more easily-readable format.
 
int main()
{
using std::ofstream; //1
using std::ifstream;
using std::cout;
using std::endl;
 
book book1("To Love and Be Wise","Josephine Tey"); //2
book book2;
 
{
ofstream fout("book.xml"); //3
 
RWObjectOutputStream out = //4
RWEnhancedXmlObjectOutputStreamImp::make(fout);
out << book1; //5
 
}
//1 Indicates that certain variables refer to their counterparts in the STD namespace.
//2 Creates two book objects, one with data, one to hold the data when you restore the object later.
//3 Creates an ofstream for writing character data to a file.
//4 Sets up an enhanced XML output stream that includes support for a transformation.
//5 Serializes the book object to a file.