Boost序列化问题
我试图在类中获取两个数组以使用 boost 序列化库。我可以很好地保存数据,但由于某种原因,我无法将其加载回来。我认为是 ia >> *这;但我不知道如何解决它。任何人都可以指出我进入正确的轨道吗?
class foo
{
private:
int tileType[512];
int tileSubType[512];
friend std::ostream & operator<<(std::ostream &os, const foo &gp);
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & tileType;
ar & tileSubType;
}
public:
foo();
void loadType(string data)
{
std::stringstream is(data);
boost::archive::text_iarchive ia(is);
ia >> *this;
}
string saveType()
{
stringstream ss(stringstream::in | stringstream::out);
boost::archive::text_oarchive oa(ss);
oa << this;
return ss.str().c_str();
}
};
I'm trying to get two arrays inside my class to use the boost serialization library. I can save the data just fine, but for some reason, I can't load it back. I think it's with ia >> *this; but I have no idea how to fix it. Anyone can point me into the right track?
class foo
{
private:
int tileType[512];
int tileSubType[512];
friend std::ostream & operator<<(std::ostream &os, const foo &gp);
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & tileType;
ar & tileSubType;
}
public:
foo();
void loadType(string data)
{
std::stringstream is(data);
boost::archive::text_iarchive ia(is);
ia >> *this;
}
string saveType()
{
stringstream ss(stringstream::in | stringstream::out);
boost::archive::text_oarchive oa(ss);
oa << this;
return ss.str().c_str();
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你尝试过吗
?
您正在保存指针但加载到引用中,我想这不是您想要的,对吧?
have you tried
?
You are saving the pointer but loading into the reference, I guess that's not what you want, right?
我在尝试对档案使用
>>
和<<
运算符时遇到了一些问题。尝试对这两种情况使用&
运算符,看看是否可以解决该问题。I ran into some problems trying to use the
>>
and<<
operators with the archives. Try using the&
operator for both cases and see if that fixes it for you.