Boost logo

Boost Users :

From: luke (lux_at_[hidden])
Date: 2005-07-07 09:08:25


Dear list

I try to read back a serialized structure (binary).
It works fine with gcc 3.3 on linux but I get problems
with visualstudio 7.1. reading back the file.

> wrong input data
> uncaught exception at: ar >> new_strucutre;

Are there some hints/ experiences with Visualstudio ??
Below I have a short code abstraction what I'm doing basically.

Thanks
  luke

==== snip ====

  struct foo
  {
    int posx;
    int posz;

    friend class boost::serialization::access;
    template<class Archive>
     void serialize(Archive & ar, const unsigned int version)
     {
       ar & posx;
       ar & posz;
     }
  };

  class Manager
  {
    public:
     Manager();
     ~Manager();

    std::vector<foo> fool_;

    friend class boost::serialization::access;
    template<class Archive>
     void serialize(Archive & ar, const unsigned int version)
     {
       ar & fool_;
     }

    private:

  };

  struct test
  {
    int id;
    int age;
    Manager manager;

    friend class boost::serialization::access;
    template<class Archive>
     void serialize(Archive & ar, const unsigned int version)
     {
       ar & id;
       ar & age;
       ar & manager;
     }

  };

  int main()
  {
    //CREATE
    test test_foo;
    test_foo.id = 1;
    test_foo.age = 2;
    foo new_foo;
    new_foo.posx = 100;
    new_foo.posz = 110;
    test_foo.manager.fool_.push_back(new_foo);

    //WRITE
    std::ofstream ofsb("filenameb");
    boost::archive::binary_oarchive ob(ofsb);
    ob << test_foo;
    ofsb.close();

    //READBACK
    std::ifstream ifs(fname.c_str(), std::ios::binary);
    boost::archive::text_iarchive ia(ifs);

    ia >> new_test; // EXCEPTION

    ifs.close();

  }

==============


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