This is a question for those who use boost in C++.
I have the following code:
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class person
{
public:
string _name;
int _age;
person (string name="Mike", int age=30):_name(name),_age(age){};
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & _name;
ar & _age;
}
};
void save()
{
ofstream file("archiv.cst");
boost::archive::binary_oarchive oa(file);
for (int i=1; i<=25; i++)
{
oa<<person("John",i);
}
file.close();
};
void load()
{
ifstream file("archiv.cst");
boost::archive::binary_iarchive ia(file);
for (int i=1; i<=25; i++)
{
person p;
ia>>p;
cout << p._name<<" " <<p._age<<endl;
}
file.close();
};
int main()
{
int i;
cin>>i;
while (i!=2)
{
if (i==0) save();
if (i==1) load();
cin>>i;
}
}
This code serializes 25 objects of type person. I also deserializes 25 objects of type person.My question to you is why this code does not work for more than 25 objects. I mean if I put 26 instead of 25 than i get a boost archive exception.
I just cannot figure out why.

New Topic/Question
Reply



MultiQuote





|