For a Character-based C++ Transformation
 
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;
 
MyInStreamTransform inTransform; //3
MyOutStreamTransform outTransform; //4
 
{
ofstream fout("book.xml"); //5
 
RWObjectOutputStream out = //6
RWTTransformObjectOutputStreamImp<MyOutStreamTransform>
::make(fout,outTransform);
out << book1; //7
out.flush(); //8
}
//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 on.
//3 Initializes the input stream transformation engine. (For the full code example, see MyInStreamTransform.h and MyInStreamTransform.cpp at buildspace\examples\xmlstreams\transform\.)
//4 Initializes the output stream transformation engine (For the full code example, see MyOutStreamTransform.h and MyOutStreamTransform.cpp at buildspace\examples\xmlstreams\transform\.)
//5 Creates an ofstream for writing character data to a file.
//6 Sets up an XML output stream that includes support for a transformation.
//7 Serializes the book object to a file.
//8 Flushes the output buffer for the XML stream, transforming the XML in the process. You may perform this explicitly, as in this line, or you may let it happen implicitly when the destructor calls flush(), and the output stream goes out of scope.