Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-07-07 10:40:42


Note that native binary archives are not guarenteed portable across
environments. text and xml archives should be. Also note that there is demo
of a portable binary archive (it doesn't handle floats) included with the
package.

On the other hand, I would expect gcc 3.3 and visual studio 7.1 to produce
binary archives which inter-operate - assuming they are both for x86
machines. It would be interesting to know where the difference comes from.

Robert Ramey

luke wrote:
> 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