如果有任何注释附加到键值,Boost属性树ini解析会出错
Boost property tree ini parsing gives error if any comment is appended to key-value
我有一个工作示例程序,它使用boost property_tree解析ini格式的数据。当我将注释附加到键值对时,我得到了coredump。我在property_tree上搜索了任何注释修剪函数,但找不到任何内容。
工作程序:
static std::string inidata =
R"(
# comment
[SECTION1]
key1 = 15
key2=val
)";
void read_data(std::istream &is)
{
using boost::property_tree::ptree;
ptree pt;
read_ini(is, pt);
boost::optional<uint32_t> sect1_key1 = pt.get_optional<uint32_t>(ptree::path_type("SECTION1/key1", '/'));
boost::optional<std::string> sect1_key2 = pt.get_optional<std::string>(ptree::path_type("SECTION1/key2", '/'));
std::cout << "SECTION1.key1: " << *sect1_key1 << std::endl;
std::cout << "SECTION1.key2: " << *sect1_key2 << std::endl;
}
附加了config:的注释
static std::string inidata =
R"(
# comment
[SECTION1]
key1 = 15 # COMMENT ADDED!
key2=val
)";
堆芯转储输出:
/usr/local/include/boost/optional/optional.hpp:992: boost::optional<T>::reference_type boost::optional<T>::get() [with T = unsigned int; boost::optional<T>::reference_type = unsigned int&]: Assertion `this->is_initialized()' failed.
Aborted (core dumped)
不支持注释样式**。
您可以通过移动文本值上的注释来看到这一点,结果是:
SECTION1.key1: 15
SECTION1.key2: val # woah
测试程序显示#
实际上只在第一个非空白列中很特别:LiveOnColiru
#include <boost/property_tree/ini_parser.hpp>
#include <iostream>
static std::string inidata =
R"(
# comment
[SECTION1]
key1 = 15
key2=val # woah
k#ey3=whoops
)";
using boost::property_tree::ptree;
void read_data(std::istream &is)
{
ptree pt;
read_ini(is, pt);
for (auto section : pt)
for (auto key : section.second)
std::cout << "DEBUG: " << key.first << "=" << key.second.get_value<std::string>() << "n";
}
#include <sstream>
int main()
{
std::istringstream iss(inidata);
read_data(iss);
}
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- C++如何将同一类的实例作为属性
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 使用内存地址访问结构的属性值
- C++调用具有 *this 属性的单个帮助程序函数
- MFC SDI在更改属性时从INI读取并更新视图字符串
- 如果有任何注释附加到键值,Boost属性树ini解析会出错
- 当INI文件不存在时,使用Boost属性树读取INI文件