提升属性树 一无是处的坏路
Boost property tree Bad path for nothing
我在这个库上遇到了问题...我的代码工作正常,解析器/创建者也可以工作,但是出现了错误,我不知道为什么:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/thread.hpp>
#include <string>
#include <exception>
#include <set>
#include <iostream>
#include "journal.h"
unsigned short port = 2013;
unsigned short maxConnec = 250;
unsigned short fPort() {return port;}
unsigned short fMaxConnec() {return maxConnec;}
bool load(const std::string &file)
{
using boost::property_tree::ptree;
ptree objectXML;
std::cout << "bbb";
read_xml(file, objectXML);
std::cout << "aaa";
if (file.length() == 0) // By the way, no way to do that better ? "if file doesn't exist..."
{
return 0;
}
else
{
port = objectXML.get<unsigned short>("configuration.server.port");
maxConnec = objectXML.get<unsigned short>("configuration.server.maxConnections");
return 1;
}
}
bool save(const std::string &file)
{
try
{
using boost::property_tree::ptree;
ptree objectXML;
objetXML.put("configuration.server.port", port);
objetXML.put("configuration.server.maxConnections", maxConnec);
write_xml(file, objectXML, std::locale(), boost::property_tree::xml_writer_make_settings<ptree::key_type>(' ', 4));
return 1;
}
catch (std::exception e)
{
return 0;
}
}
void generate()
{
std::string file = "configuration.xml";
try{
if (!load(fichier))
{
save(file);
}
}
catch (std::exception &e)
{
load(file);
}
}
得到一个糟糕的路径,我完全不知道为什么,因为当我尝试读取数据时,我可以并且即使我更改它,它也会在configuration.xml
中获取数据......
ptree_bad_path
异常是从 get
的抛出版本引发的,并发出"configuration.server.port"
或 XML 元素路径不存在"configuration.server.maxConnections"
信号。
该错误与configuration.xml
文件路径无关。
因此,您应该检查元素名称,或者对于可选元素,请使用 get
的默认值/可选值版本。
相关文章:
- 数到第n个楼梯的路(顺序无关紧要)
- vscode g++链路故障:体系结构x86_64的未定义符号
- 这是实现图形的坏方法吗
- 将树节点添加到向量向量中的 n 元树遍历的平均和最坏情况时间复杂度是多少?
- GLFW DDS 加载函数的 OpenGL 链路错误
- C++ - 最坏情况和平均情况插入时间复杂度在 std::unordered_map <int,int>?
- QBS 为静态链路 MSVC 创建静态库
- 如何在C++中创建类型列表的 n 路笛卡尔积?
- 实现 3 路分区以实现快速排序
- wxWidgets mac剪贴板在3.1.3上坏了?
- 如何为 opencv 安装 gstreamer 1.0 坏插件?
- 3路随机快速排序分区功能
- 计时器坏了或者其他什么的
- 在最坏的情况下试验快速排序.它运行良好,但在最坏的情况下发生未知错误.我想
- boost::p rocess::env 在 ubuntu 19.04 上坏了?
- 如何通过自定义的流设置流的坏位
- 通往GCC_ARM之路 (mbed_settings.py)
- std::regex 是否保证了最坏情况下的时间复杂度?
- 课堂上的一行,使整个应用程序坏了. 0xC000005错误
- 提升属性树 一无是处的坏路