gpt4 book ai didi

c++ - boost 序列化stringstream错误

转载 作者:行者123 更新时间:2023-11-30 02:09:17 25 4
gpt4 key购买 nike

所以...

每当我运行以下命令时:

#inlcude <iostream>
#include <sstream>

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

using namespace std;

class gps_position
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees;
ar & minutes;
ar & seconds;
}
int degrees;
int minutes;
float seconds;
public:
gps_position(){};
gps_position(int d, int m, float s) :
degrees(d), minutes(m), seconds(s)
{}
};

int main() {
stringstream ss1;

const gps_position g(35, 59, 24.567f);

{
boost::archive::text_oarchive oa(ss1);
oa << g;
}

gps_position newg;
{
stringstream ss2;
boost::archive::text_iarchive ia(ss2);
ia >> newg;
}
return 0;
}

我收到以下错误:

terminate called after throwing an instance of 'boost::archive::archive_exception'
what(): output stream error
Aborted

所以...这让我感到困惑...任何帮助都会很棒!

谢谢!

最佳答案

main 中填充 ss1,然后创建一个名为 ss2 的新 std::stringstream 并尝试从中读取。您希望它如何工作?很明显 ss2 不包含任何数据。

关于c++ - boost 序列化stringstream错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5600782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com