如何序列化boost :: uuids :: uuid

我目前在项目中使用boost :: uuids :: uuid,我想序列化包含boost :: uuids :: uuid的对象。 我尝试了下面的简单示例,但出现错误:

/usr/include/boost/archive/basic_text_oprimitive.hpp:92:错误:'((boost :: archive :: basic_text_oprimitive> *)this'中的'operator <<'不匹配) - > boost :: archive :: basic_text_oprimitive > :: os << t'

如果有人能够帮助我,我会真正感到满意。

#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;
}

包含<boost/uuid/uuid_serialize.hpp>以启用uuids的序列化。 http://www.boost.org/doc/libs/1_42_0/libs/uuid/uuid.html#boost/uuid/uuid_serialize.hpp

链接地址: http://www.djcxy.com/p/10789.html

上一篇: how to serialize boost::uuids::uuid

下一篇: How to name graphic files for iPad 3