C++ 提升序列化提升::archive_exception:输出流错误
C++ Boost Serialization boost::archive_exception: Output stream error
我正在使用 Boost 序列化库运行以下C++代码,该库首先序列化类 Info 的对象,然后将其检索回类 Info 的另一个对象:
#include <vector>
#include <fstream>
#include <boost/serialization/vector.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
class Info
{
private:
// Allow serialization to access non-public data members.
friend class boost::serialization::access;
// Serialize the std::vector member of Info
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & filenames;
}
std::vector<std::string> filenames;
public:
void AddFilename( const std::string& filename );
void Print() const;
};
void Info::Print() const
{
std::copy(filenames.begin(), filenames.end(), std::ostream_iterator<std::string>(std::cout, "n"));
}
void Info::AddFilename( const std::string& filename )
{
filenames.push_back( filename );
}
int main(int argc, char** argv)
{
Info info;
info.AddFilename( "ThisFile.txt" );
info.AddFilename( "ThatFile.txt" );
info.AddFilename( "OtherFile.txt" );
// Save filename data contained in Info object
{
// Create an output archive
std::ofstream ofs( "store.dat" );
boost::archive::text_oarchive ar(ofs);
ar & info;
}
// Restore from saved data and print to verify contents
Info restored_info;
{
// Create and input archive
std::ifstream ifs( "store.dat" );
boost::archive::text_iarchive ar(ifs);
// Load the data
ar & restored_info;
}
restored_info.Print();
return 0;
}
我收到以下错误:terminate called after throwing an instance of 'boost::archive::archive_exception'
what(): output stream error
Aborted (core dumped)
如果有人能在这里帮助我,那就太好了。
谢谢。
添加LD_LIBRARY_PATH可以解决问题
LD_LIBRARY_PATH = pathtoboostlib
export $LD_LIBRARY_PATH
相关文章:
- 如何在C++中编写 ostream 的向量,它接收所有不同的输出流,如 cout、ostringstream 和 ofs
- 在输出流中插入换行符
- 在类外部重载输入和输出流
- 通用容器的输出流
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 获取C++输出流中元素的大小
- 用于了解输入和输出流缓冲区实际工作方式的程序
- 控制多线程程序中的输出流
- 为什么输出流首选" "而不是""?
- C++ 输出流运算符 <<() 中的字符何时加宽?
- 音频缓冲区列表,用于输出流格式已压缩的 AUHAL 单元
- 如何将值发送到标准输出流并在另一个程序中访问这些值
- 我必须如何将OpenCV输出流到我自己的远程C GUI
- 如何为提升日志和自定义类型定义输出流运算符
- 修改视频帧并将其发送回视频输出流
- 组合输入和输出流
- C++ 中的递增/递减和输出流运算符优先级
- C++输出流到文件不起作用
- 输出流中的运算符优先级C++