【问题标题】:Can't use boost::stream with std::string<unsigned char> to instanciate boost::binary_oarchive or boost::binary_iarchive不能将 boost::stream 与 std::string<unsigned char> 一起使用来实例化 boost::binary_oarchive 或 boost::binary_iarchive
【发布时间】:2016-05-30 10:27:03
【问题描述】:

开发者加油,

我在使用下一个代码时遇到了问题(Visual Studio 2015 编译器):

template<typename SERIALIZABLE_TYPE, typename BUFFER_TYPE>
inline void Serialize::IntoStringBuffer(const SERIALIZABLE_TYPE& object, BUFFER_TYPE& strBuffer)
{
    back_insert_device<BUFFER_TYPE> inserter(strBuffer);
    stream<back_insert_device<BUFFER_TYPE>> aStream(inserter);

    binary_oarchive binaryOutArchive(aStream);
    binaryOutArchive & object;

    aStream.flush();
}

template<typename SERIALIZABLE_TYPE, typename BUFFER_TYPE>
inline void Types::Serialize::FromStringBuffer(const BUFFER_TYPE& strBuffer, SERIALIZABLE_TYPE& object)
{
    basic_array_source<typename BUFFER_TYPE::value_type> arraySource(strBuffer.data(), strBuffer.size());
    stream<basic_array_source<typename BUFFER_TYPE::value_type>> aStream(arraySource);

    binary_iarchive binaryInArchive(aStream);
    binaryInArchive & object;
}

当我将这些助手与序列化对象和 std::string 缓冲区一起使用时,解决方案构建。

但是,我必须使用带有 unsigned char 类型的 std::basic_string 作为缓冲区。然后,解决方案不再编译:

error C2664: 'boost::archive::binary_iarchive::binary_iarchive(const boost::archive::binary_iarchive &)' : impossible de convertir l'argument 1 de 'boost::iostreams::stream<boost::iostreams::basic_array_source<unsigned char>,std::char_traits<_Elem>,std::allocator<_Ty>>' en 'std::istream &' with[_Elem=unsigned char,_Ty=unsigned char]

error C2664: 'boost::archive::binary_oarchive::binary_oarchive(const boost::archive::binary_oarchive &)' : impossible de convertir l'argument 1 de 'boost::iostreams::stream<boost::iostreams::back_insert_device<BUFFER_TYPE>,std::char_traits<_Elem>,std::allocator<_Ty>>' en 'std::ostream &' with [ BUFFER_TYPE=std::basic_string<unsigned char>, _Elem=unsigned char, _Ty=unsigned char]

我无法确定究竟是哪个问题?以及如何解决?

一些建议?

最好的问候。

【问题讨论】:

    标签: c++ boost stream boost-serialization unsigned-char


    【解决方案1】:

    问题是不支持无符号字符流。

    这也没有必要。无论如何,事情都是二进制的。 std::ios::binary 模式下的任何流缓冲区都可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      相关资源
      最近更新 更多