Boost logo

Boost Users :

From: Filip Peters (filippeters_at_[hidden])
Date: 2005-07-07 11:59:22


Hi,

seems you're mixing binary and text?
you're reading in text in your example...

> //WRITE
> std::ofstream ofsb("filenameb");
> boost::archive::binary_oarchive ob(ofsb);

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

Also, I had to do
std::ofstream ofsb("filenameb", std::ios::binary);
before it would work correctly.

(I started using boost/serialization this week and
also had some issues at first (with vc7.1), but it's
working nicely now)
The serialisation lib is quite nice!

Filip Peters.

 
--- luke <lux_at_[hidden]> 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 mailing list
> Boost-users_at_[hidden]
>
http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

                
____________________________________________________
Sell on Yahoo! Auctions no fees. Bid on great items.
http://auctions.yahoo.com/


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