******************************************************************************
I have used the following code sample to save a tree structure to a file:
but when i load back the structure from the file,i dont get any data.
To load the structure,i use:
And finaly,the code i've used to create the tree is:
the file header "tree.hh" is an STL-like container class for n-ary trees,it can be found in the following address:
I have used the following code sample to save a tree structure to a file:
Code:
fp = fopen( "tree.dat", "wb" );
if( !fp ) {
cerr << "Error while saving tree" << endl;
break;
}
fwrite( &tr, sizeof(tr), 1, fp );
To load the structure,i use:
Code:
fp = fopen( "tree.dat", "rb" );
if( !fp ) {
cerr << "Error while loading tree" << endl;
break;
}
fread( &tr, sizeof(tr), 1, fp )
Code:
#include <algorithm>
#include <string>
#include <iostream>
#include "tree.hh"
using namespace std;
....
.....
tree<string> tr;
tree<string>::iterator top, one, two, loc, banana;
top=tr.begin();
one=tr.insert(top, "one");
two=tr.append_child(one, "two");
tr.append_child(two, "apple");
banana=tr.append_child(two, "banana");
tr.append_child(banana,"cherry");
tr.append_child(two, "peach");
tr.append_child(one,"three");
...
the file header "tree.hh" is an STL-like container class for n-ary trees,it can be found in the following address: