Boost logo

Boost Users :

Subject: Re: [Boost-users] multiple serialized objects to same file
From: Niklas Angare (li51ckf02_at_[hidden])
Date: 2010-08-21 14:49:46

"Oscar Pernas" <oscar_at_[hidden]> wrote:
> Is posible with boost serialization to write different objects to
> the same file?

Yes. Just serialize them one after the other:
ar << x;
ar << y; // Not necessarily the same type as x

All that matters is that you deserialize the same types in the same order.

> is possible to access to each object with an
> iterator or with position like binary files?

I'm not sure what you mean. Can you give an example? There is no random
access to archives.

If the number of objects isn't known at compile time you could serialize the
count first so that the deserialization code can find out how many to
deserialize. You could also put your objects in an STL container, a vector
for example, and serialize that.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at