Thank you, Robert.
I really want to konw why the program can run successful when using
mingw to compile, and will crash when using vc71 to compile.
I have debug and trace into the code, I found when I execute
pbb->Load( ifs );, it will call this function:
basic_text_iarchive<Archive>::init(void){
// read signature in an archive version independent manner
std::string file_signature;
* this->This() >> file_signature;
if(file_signature != ARCHIVE_SIGNATURE())
boost::throw_exception(
archive_exception(archive_exception::invalid_signature)
);
the file_signature is empty, so throw the exception invalid_signature.
Can you tell me, why it like this?
2008/1/2, Robert Ramey
Rather than put your program on my debugger, here is the way I anticipated that the library would be used:
#include <iostream>
#include <fstream>
#include
#include #include //---------------------------------------------------------------------------- using namespace std;
//---------------------------------------------------------------------------- class A { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & a; ar & b; }
public: int a; int b;
};
//---------------------------------------------------------------------------- class B { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & ms; ar & a; } public:
public: B( const string& s ) : ms( s ){} void print(){ cout << ms << endl; } private: B(){} // use by serialization only string ms; A a; };
//---------------------------------------------------------------------------- int main() { // Save A* pa = new A; pa->a = 3; pa->b = 5;
B* pb = new B( "this is test B" );
{ std::ofstream ofs( "all.out" ); boost::archive::text_oarchive oa(ofs);
oa << pa; ob << pb;
delete pa; delete pb; } A* paa; B* pbb { std::ifstream ifs( "all.out", std::ios::binary );
boost::archive::text_oarchive ia(ifs); ia >> paa; ia >> pbb; }
cout << "A: " << paa->a << " " << paa->b << endl; pbb->print();
delete paa; delete pbb; return 0; }
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users