1

So...

Whenever I run the following:

#inlcude <iostream>
#include <sstream>

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

using namespace std;

class gps_position
{
private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & degrees;
        ar & minutes;
        ar & seconds;
    }
    int degrees;
    int minutes;
    float seconds;
public:
    gps_position(){};
    gps_position(int d, int m, float s) :
        degrees(d), minutes(m), seconds(s)
    {}
};

int main() {
    stringstream ss1;

    const gps_position g(35, 59, 24.567f);

    {
        boost::archive::text_oarchive oa(ss1);
        oa << g;
    }

    gps_position newg;
    {
        stringstream ss2;
        boost::archive::text_iarchive ia(ss2);
        ia >> newg;
    }
    return 0;
}

I get the following error:

terminate called after throwing an instance of 'boost::archive::archive_exception'
   what():   output stream error
Aborted

So... This baffles me... any help would be GREAT!

Thanks!

1 Answer 1

4

In main you populate ss1, then create a new std::stringstream called ss2 and try to read from that. How would you expect this to work? It's clear that ss2 contains no data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.