gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:52:07 27 4
gpt4 key购买 nike

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

/usr/include/boost/archive/basic_text_oprimitive.hpp:92: 错误: '((boost::archive::basic_text_oprimitive >*)this)->boost::archive 中的 'operator<<' 不匹配::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>启用 uuid 的序列化。 http://www.boost.org/doc/libs/1_42_0/libs/uuid/uuid.html#boost/uuid/uuid_serialize.hpp

关于serialization - 如何序列化 boost::uuids::uuid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10755794/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com