C++11 C++;boost序列化错误:[boost::archive::archive类型的未捕获异常\u异常:输入流错误无此类进程]

C++11 C++;boost序列化错误:[boost::archive::archive类型的未捕获异常\u异常:输入流错误无此类进程],c++11,boost,c++14,c++17,C++11,Boost,C++14,C++17,我得到一个错误“libc++abi.dylib:以boost::archive::archive类型的未捕获异常终止\u异常:输入流错误在我的程序中没有这样的进程” 我的节目: class fruits{ public: void set(int apple, int mango, int banana){ m_apple = apple; m_mango = mango; m_banana = banana; } int app

我得到一个错误“libc++abi.dylib:以boost::archive::archive类型的未捕获异常终止\u异常:输入流错误在我的程序中没有这样的进程”

我的节目:

class fruits{
public:
    void set(int apple, int mango, int banana){
        m_apple = apple;
        m_mango = mango;
        m_banana = banana;
    }

int apple(){return m_apple;}
int mango(){return m_mango;}
int banana(){return m_banana;}
private:
    int m_apple, m_mango, m_banana;
    friend boost::serialization::access;

template<typename Archive>
void serialize(Archive & arc, unsigned int version){
    arc & BOOST_SERIALIZATION_NVP(m_apple);
    arc & BOOST_SERIALIZATION_NVP(m_mango);
    arc & BOOST_SERIALIZATION_NVP(m_banana);
}
};

void save(std::string fname){
    fruits _fruits;
    _fruits.set(1, 2, 3);
    std::ofstream of(fname.c_str());
    boost::archive::xml_oarchive of_xml(of);
    of_xml & BOOST_SERIALIZATION_NVP(_fruits);
    of.close();

}

void load(std::string fname){
    fruits _fruits;
    std::ifstream inf(fname.c_str());
    boost::archive::xml_iarchive inf_xml(inf);
    inf_xml & BOOST_SERIALIZATION_NVP(_fruits);

    std::cout<<"apple : "<<_fruits.apple()<<" mango : "<< _fruits.mango()<<" banana : "<<_fruits.banana()<<"\n";

}

int main(){

    std::string fname = "fruits.xml";

    save(fname);
    load(fname);  // this function gives error

    return 0;
}
类水果{
公众:
空集(整数苹果、整数芒果、整数香蕉){
苹果=苹果;
芒果=芒果;
m_香蕉=香蕉;
}
int apple(){return m_apple;}
int mango(){return m_mango;}
int banana(){return m_banana;}
私人:
苹果、芒果、香蕉;
friend boost::serialization::access;
模板
无效序列化(存档和arc,未签名整数版本){
arc&BOOST_系列化_NVP(苹果公司);
arc&BOOST_系列化_NVP(芒果);
arc&BOOST_系列化_NVP(m_香蕉);
}
};
无效保存(std::string fname){
水果;
_果.套(1,2,3);
(fname.c_str())流的std::of;
boost::archive::xml\u-oarchive of\u-xml(of);
xml和BOOST序列化NVP(_fruits);
of.close();
}
无效加载(标准::字符串fname){
水果;
std::ifstream inf(fname.c_str());
boost::archive::xml\u iarchive inf\u xml(inf);
inf\uxml和BOOST\userialization\unvp(\ufruits);
标准::cout