多次加载属性树xml解析器异常

Multiple loads of property tree xml-parser exception

本文关键字:异常 xml 加载 属性      更新时间:2023-10-16

我正在使用属性树xml解析来编辑应用程序的一些设置我创建了一个struct default-settings

struct default_settings
{
    std::string imPath;          
    std::string calPath;
    std::string solPath;
    void load(const std::string &filename);
    void save(const std::string &filename,const std::string &image_path,const std::string &cal_path,const std::string &sol_path);
};
void default_settings::save(const std::string &filename,const std::string &image_path,const std::string &cal_path,const std::string &sol_path)
{
    ptree pt;
    pt.put("default.image-path", image_path);
    pt.put("default.cal-path", cal_path);
    pt.put("default.sol-path", sol_path);
    write_xml(filename, pt);    
}
void default_settings::load(const std::string &filename)
{
    ptree pt;
    read_xml(filename, pt);
    imPath = pt.get<std::string>("default.image-path");
    calPath = pt.get<std::string>("default.cal-path");
    solPath = pt.get<std::string>("default.sol-path");

}

和I访问变量:imPath, calPath,…等通过在我的应用程序中创建一个全局变量default_settings ds并通过这个变量(ds.imPath)

调用它们

奇怪的是,当加载完成一次时,它可以工作,但我得到一个异常

boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::xml_parser::xml_parser_error> > at memory location 0x0016bf54..

你有什么建议?

问题是使用const std::string作为参数!