I'm currently using boost::uuids::uuid in a project and I want to serialize objects containin boost::uuids::uuid. I tried the simple example below but I get an error:
/usr/include/boost/archive/basic_text_oprimitive.hpp:92: error: no match for ‘operator<<’ in ‘((boost::archive::basic_text_oprimitive >*)this)->boost::archive::basic_text_oprimitive >::os << t’
I would really appriciate if someone could help me.
#include <fstream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_serialize.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
class classA {
public:
classA() : id(boost::uuids::random_generator()()) {}
private:
friend class boost::serialization::access;
boost::uuids::uuid id;
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & id;
}
};
int main(void) {
classA a;
std::ofstream ofs("uuid.txt");
boost::archive::text_oarchive oa(ofs);
oa << a;
ofs.close();
return 0;
}
Include <boost/uuid/uuid_serialize.hpp>
to enable serialization for uuids.
http://www.boost.org/doc/libs/1_42_0/libs/uuid/uuid.html#boost/uuid/uuid_serialize.hpp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With