c++ - 如何使用cerial序列化

标签 c++ serialization cereal

我试图弄清楚 Cereal 序列化是如何工作的,所以我阅读了文档(我发现它有点缺乏 imo)并尝试重现它们在其中的代码:

#include <sstream>
#include <archives/binary.hpp>

struct MyData
{
  int x, y, z;

  // This method lets cereal know which data members to serialize
  template<class Archive>
  void serialize(Archive & archive)
  {
    archive( x, y, z ); // serialize things by passing them to the archive
  }
};

int main()
{
    std::stringstream ss; // any stream can be used

     {
       cereal::BinaryOutputArchive oarchive(ss); // Create an output archive

       MyData m1, m2, m3;
       oarchive(m1, m2, m3); // Write the data to the archive
     } // archive goes out of scope, ensuring all contents are flushed

     {
       cereal::BinaryInputArchive iarchive(ss); // Create an input archive

       MyData m1, m2, m3;
       iarchive(m1, m2, m3); // Read the data from the archive
     }

    return 0;
}

我直接从 Cereal 的文档中复制了代码,但我一直收到错误提示:

type 'cereal::BinaryInputArchive' 不提供调用运算符

最佳答案

显然我没有正确包含库,这解决了问题。

关于c++ - 如何使用cerial序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53363951/

相关文章:

基于Java的memcached客户端,优化将数据放入memcache

java - 用于泛型类型的 Jackson 反序列化器

c++ - Boost 序列化在 32 位和 64 位机器之间不起作用。任何其他序列化/压缩库?

c++ - 在 Windows 桌面应用程序中使用第三方 C++ 库

c++ - 无法插入到 std::map (G++)

java - 从复杂的服务器响应中提取字段

c++ - Cereal:序列化多态类型

c++ - 如何用 Cereal 序列化 boost::uuid

c++ - 复制构造函数、深拷贝以及如何正确编写

c++ - 删除和修改 Boost MultiIndex 容器中的元素