我正在尝试使用带有 boost 的默认序列化工具,但我没有设法序列化复杂的向量。我试过这个:
#include <fstream>
#include <complex>
#include <vector>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/complex.hpp>
using namespace std;
typedef complex<double> type;
template<class Archive>
void serialize(Archive& ar, vector<type>& objs, const unsigned version) {
ar & objs;
}
int main(){
vector<type> r;
r.push_back(1.3);
r.push_back(12.12);
r.push_back(-31.05);
ofstream ofs("test.txt");
boost::archive::text_oarchive oa(ofs);
oa & r;
return 0;
}
它编译得很好,但在执行时崩溃。然而,如果我这样做
typedef double type
然后一切正常。我想不出解决办法。有什么帮助吗?
谢谢,
简