|
Boost Users : |
From: sjdf (sjdf.maillist_at_[hidden])
Date: 2008-01-02 02:54:28
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 <ramey_at_[hidden]>:
> 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 <boost/serialization/string.hpp>
> > #include <boost/archive/text_oarchive.hpp>
> > #include <boost/archive/text_iarchive.hpp>
> >
> >
> > //----------------------------------------------------------------------------
> > 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net