Windows中的boost :: serialization的未知异常

Nee*_*asu 1 c++ exception boost-serialization

这是我尝试过的,但我被Error: Unknown exception抛出了

try{//load
  std::ifstream stream(arch_name.c_str());
  std::cout << ">> " << "Started deserializing " << arch_name << std::endl;
  boost::archive::binary_iarchive arc(stream);
  arc & c & matrix;
  stream.close();
  std::cout << ">> " << "Finished deserializing" << std::endl;
}catch(std::exception e){
  std::cout << "Error: " << e.what() << std::endl;
  return 1;
}
Run Code Online (Sandbox Code Playgroud)

这在使用gcc的Linux中运行良好.我在Windows中使用Visual Studio.

编辑

backtrace显示basic_binary_iprimitive.hpp正在抛出异常

template<class Archive, class Elem, class Tr>
inline void basic_binary_iprimitive<Archive, Elem, Tr>::load_binary( void *address,     std::size_t count){
//.....
if(scount != s)
    boost::serialization::throw_exception(
        archive_exception(archive_exception::input_stream_error)
    );
Run Code Online (Sandbox Code Playgroud)

编辑

我改变了catch黑色catch(boost::archive::archive_exception e)并打印出来.input stream error

在虚拟环境中有什么错过提升存档异常吗?

rrw*_*ick 5

我遇到了这个问题,因为我遇到了同样的问题 - Windows上的提升序列化异常.我在Greg的评论中找到了解决方案:在创建数据流时定义i/o模式.

我改变了这个:

std::ofstream ofs(filename);
boost::archive::binary_oarchive ar(ofs);
Run Code Online (Sandbox Code Playgroud)

对此:

std::ofstream ofs(filename, std::ios::binary);
boost::archive::binary_oarchive ar(ofs);
Run Code Online (Sandbox Code Playgroud)

然后在反序列化时不再发生异常!

我认为这个问题需要一个真正的答案(不仅仅是一个评论),所以我自己添加它,但所有的功劳归于Greg.