Boost logo

Boost Users :

From: Surya Kiran Gullapalli (suryakiran.gullapalli_at_[hidden])
Date: 2007-02-21 04:29:10


Hello all,
I'm a newbie to boost serialization and i need some help.

I'm using boost serialization, to serialize a class, which contains 3
std::string members.

After i serialize i add it to a database. The database I'm using is
berkeley-db. The database API needs key/data pair, both in void* type.

Now for my problem,

the key is std::string, so I'm passing in key as (void *)key.c_str(),
I know its crude, but i'm just starting.

Now for the data part, I've to serialize the complete class. As,
boost::archive::binary_oarchive, takes ostream& as argument for
constructor, I've done like this.

std::ostringstream os ;
boost::archive::binary_oarchive oa (os) ;
oa << class_obj ;

so the class_obj has been written to os. so i'm sending data to db api as
(void *)os.str().c_str().

To retrieve data, I'm using something like this

data=db.get_data() ;
istringstream is((char *)data) ;
boost::archive::binary_iarchive (is) ;

The code compiled fine and at run time i'm getting exception
basic::string::resize during construction of binary_iarchive.

Obviously i was doing wrong. My question is how to serialize data and
write it to memory than to a file? and how do i access it again?

Thanks in advance,
Surya


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