Hi all,
I am having following problem while reading the data out of the file using one of the sample program provided in boost serialization example online. I am trying to read the file having multiple gps_position objects but getting following exception. Can someone please let me know what might be the problem here. Let me know if you need any more information:
#include <fstream>
#include <string>
// include headers that implement a archive in simple text format
#include
#include
#include
#include
#include
/////////////////////////////////////////////////////////////
// gps coordinate
//
// illustrates serialization for a simple type
//
class gps_position
{
private:
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees;
ar & minutes;
ar & seconds;
ar & day;
}
public:
int degrees;
int minutes;
float seconds;
std::string day;
gps_position(){};
gps_position(int d, int m, float s, std::string inDay) :
degrees(d), minutes(m), seconds(s), day(inDay)
{}
};
int main() {
// create and open a character archive for output
std::ofstream ofs("filename");
// create class instance
const gps_position g(35, 59, 24.567f, "Monday_Pointer");
const gps_position g1(45, 69, 34.567f, "Tuesday_Pointer");
const gps_position * g2 = new gps_position(1,2,3.3, "WEDNESDAY_PTR");
{
boost::archive::text_oarchive oa(ofs);
oa << g;
oa << g1;
oa << (*g2);
}
{
/**gps_position g;
std::vector vec;
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
while (!ifs.eof()) {
std::cout << " ++++++++++++++++ " << std::endl;
ia >> g;
std::cout << g.degrees << " : "
<< g.minutes << " : "
<< g.seconds << " : "
<< g.day < gps;
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
ia >> gps;
for (int i = 0; i < gps.size(); ++i) {
std::cout << gps[i].degrees << " : "
<< gps[i].minutes << " : "
<< gps[i].seconds << " : "
<< gps[i].day <