我需要在客户端和服务器之间传输数据。当我将服务器从 Windows (msvc140) 移动到 Debian (gcc 64 位) 时,我的字节流类出现了问题boost
。他们的档案是不同的。
#include <string>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/stream.hpp>
int main()
{
std::string s;
typedef boost::iostreams::back_insert_device<std::string> BackInsertDevice;
typedef boost::iostreams::stream<BackInsertDevice> Stream;
typedef boost::archive::binary_oarchive BinaryOArchive;
Stream stream(s);
BinaryOArchive ar(stream);
ar << "qwer" << 10;
stream.flush();
int sz = s.size();
// Windows (msvc140): 49
// Debian (gcc 64-bit): 57
}
两个版本boost
是 1.61.0
这是有记录的。http://www.boost.org/doc/libs/1_49_0/libs/serialization/doc/todo.html#portablebinaryarchives
Boost 本身没有可移植的存档。
您想查看 EOS 便携式档案:https://epa.codeplex.com/
它们很容易放入您的代码库中并使用,而不是boost::archive::binary_[io]archive
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)