boost binary_oarchive对于不同的编译器工作不同 [英] boost binary_oarchive works differently for different compilers
问题描述
我需要在客户端和服务器之间传输数据。当我把服务器从Windows(msvc140)移动到Debian(gcc 64位)我有一个问题,我的字节流类基于 boost
。他们的档案不同。
I need to transfer data between client and server. When I moved server from Windows (msvc140) to Debian (gcc 64-bit) I've got a problem with my byte stream class based on boost
. Their archives are different.
#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
Both versions of boost
are 1.61.0
推荐答案
这是文件。 http://www.boost.org/doc /libs/1_49_0/libs/serialization/doc/todo.html#portablebinaryarchives
Boost本身没有可移动存档。
There is no portable archive in Boost itself.
您要查看EOS便携式档案馆: https://epa.codeplex.com/
You want to look at EOS Portable Archives: https://epa.codeplex.com/
他们很容易放在你的代码库中,而不是 boost :: archive :: binary_ [io] archive
They're very easy to drop in your code base and use instead of boost::archive::binary_[io]archive
这篇关于boost binary_oarchive对于不同的编译器工作不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!