boost 序列化 博客分类: c++boost boost序列化
程序员文章站
2024-03-06 13:38:20
...
在用boost 二进制序列化类的时候,需要注意动态调用文件打开标志std::ios::binary:
The flag std::ios::binary is required only in Windows, where the default mode (ascii) would translate \n\r to \n (and vice versa), thus corrupting any data that is not textual.
The flag std::ios::binary is required only in Windows, where the default mode (ascii) would translate \n\r to \n (and vice versa), thus corrupting any data that is not textual.
#include <boost/serialization/string.hpp> #include "boost/archive/binary_oarchive.hpp" #include "boost/archive/binary_iarchive.hpp" #include "boost/iostreams/stream.hpp" #include <boost/serialization/version.hpp> typedef struct tagWorkStruct { string groundTruthFile; string jpegFile; int workId; }WorkStruct; template<class Archive> void serialize(Archive &ar, AddNewCardWorkStruct &g, const unsigned int version) { ar & g.groundTruthFile; ar & g.jpegFile; ar & g.workId; } //写入文件 string fileName = "test.dat"; ofstream os(fileName.c_str(), std::ios::binary); if (!os.fail()) { try { WorkStruct tempStruct; boost::archive::binary_oarchive oa(os); oa << tempSturct; } catch(...) { } } //读取文件 ifstream is(dataFileName.c_str(), std::ios::binary); if (!is.fail()) { try { WorkStruct tempStruct; boost::archive::binary_iarchive ia(is); ia >> tempStruct; } catch (...)//boost::archive::archive_exception { } }
上一篇: Android的支付密码输入框实现浅析
下一篇: ASP.NET MVC3的伪静态实现代码
推荐阅读
-
Boost 使用 博客分类: C/C++ vs10Boostc++标准库asio
-
[C++]boost::unique_lock与boost::lock_guard区别 博客分类: C/C++ boost
-
C++17 std::shared_mutex的替代方案boost::shared_mutex 博客分类: C/C++ C++17boost
-
[boost]VS2015编译构建boost 1.60 博客分类: C/C++ boost
-
boost 序列化 博客分类: c++boost boost序列化
-
hadoop_AVRO数据序列化系统_简介 博客分类: HaDoop学习笔记AVRO数据序列化系统 Avro简介avro数据模式
-
Ofbiz XML-Rpc 反序列化漏洞 博客分类: ofbiz
-
php 序列化(serialize)格式详解 博客分类: php php serialize
-
Oracle中的序列化问题 博客分类: 数据库 Oracle编程SQL ServerSQLCache
-
json-lib 序列化和反序列化 博客分类: Java json-lib反序列化序列化java对象SerializetoBean