- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个以下格式的文件,我正在尝试使用 boost::property_tree::read_ini 和 boost::property_tree 来解析。
示例配置文件(一些值包含空格)
[Config]
A = 1000
B.x = Test
B.y = Test By
C.x.y = Test_Cxy
C.x.z = Test Cxz
[Config2]
...
示例代码
boost::property_tree::ptree config;
boost::property_tree::read_ini (name, config);
// Correctly Iterates through and displays correct pairs
for (ptree::const_iterator it = pt.begin(); it != end; ++it) {
std::cout << it->first << ": " << it->second.get_value<std::string>() << std::endl;
print(it->second);
}
const boost::property_tree::ptree& configTree = config.get_child("Config");
// Correctly gets A
std::string test_ = configTree.get<std::string>("A", "Default");
// Doesn't get B.x
std::string test_ = configTree.get<std::string>("B.x", "Default");
我做错了什么?如何正确获取 B.x、B.y 等? B.x 是否被视为 B 的 child ?因此我需要获取 B 的 get_child?
最佳答案
属性树是一种分层数据结构,其中每个节点都可以有一个有序的子节点序列。从这个意义上说,属性树比平面 ini 文件更类似于 XML。虽然它可以从 ini 文件和 XML 初始化,但它代表的内部数据都是一样的,查询“x.y.z”具有选择 x 的 y 子节点的 z 子节点的特殊含义。
它归结为属性树的 string_path
类,它具有默认分隔符 。
,
/// Default path class. A path is a sequence of values. Groups of values
/// are separated by the separator value, which defaults to '.' cast to
/// the sequence's value type. The group of values is then passed to the
/// translator to get a key.
总的来说,要么在使用 ini 文件时避免在项目名称中使用点,要么通过显式构建路径来更改分隔符:
configTree.get<std::string>(ptree::path("B.x", '/')); // using non-default separator
关于c++ - 使用 boost::property_tree 读取 ini 文件不适用于表单 A.x 的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20990830/
PHP 解释器是否首先加载它找到的 php.ini(根据其搜索算法)并停止。还是加载整个 php.ini 层次结构并合并设置? 因此,如果我需要覆盖单个网站的单个设置 - 我需要指定所有值,还是只需要
关于以下形式的归并排序算法: public static void merge(int [] a, int ini, int med, int end){ int [] b = new
如何从另一个 ini 文件解析变量? 在下面的例子中,我想解析 var_a来自 original_configuration.ini并在 new_configuration.ini 使用它 origi
我无法获取 ini 文件中数组的值。 这是 ini 文件: module.name = Core module.version = 1 module.package = 'Core Modules'
编辑 eclipse.ini (OS Ubuntu 12.04 LTS) 后无法保存。如何在 eclipse.ini 文件或任何其他 .ini 文件中进行更改? Eclipse 和 Scala IDE
我目前正在使用 Zend Framework 从事个人项目。我一直无法获得良好的搜索结果,也没有问过我的同事:-/。 我在工作中经常使用 Ant/Phing,你有一个叫做“属性文件”的东西,它们有这个
我想提高我的 mysql 性能。所以我尝试使用 my-large.ini。 首先,我将该文件重命名为 my.ini。然后我在 [mysqld] 下添加了以下行 port=3306 basedir="C
我似乎遇到了一个问题,但感觉它不是一个问题,但我看不到解决方案,所以也许其他人可以。 我正在使用 ini 文件来存储我正在编写的包的配置详细信息。此 ini 文件包含与其他 ini 文件相关的部分。
我正在使用 Java API ini4j解析 ini 文件。我的原始 .ini 文件具有以下键值格式: [section] key=value = 字符周围没有空格。 但是在使用 ini.store(
我有写一段 ini 文件的函数: boolean saveSSVar() { using boost::property_tree::ptree; ptree pt; pt.p
最近我在 ubuntu 16.04 机器上安装了 lamp 和 php-xdebug。我注意到现在我有以下文件 /etc/php/7.0/apache2/conf.d/20-xdebug.ini /e
我正在尝试为我的 Pyramid 项目配置 SQLAlchemy Alembic,我想使用我的 developement.ini(或 production.ini)来配置 Alembic。是否可以指定
我的 FlashBuilder 实例在进行一些繁重的分析时不断崩溃。 必须说,我也在生成对象分配跟踪(全部,而不是默认的 10 个)并大量遍历 GC 路径。 但是我有一种预感,我可以通过允许 Flas
我是网络世界的新手,想知道当服务器默认 php.ini 文件时,自定义 php.ini(我们手动创建并添加到每个目录) 文件,.user.ini 文件由服务器加载/读取? 根据我的概念,这些文件在每次
在创建组件时,我在Joomla的组件目录结构中看到了两个语言文件:.ini和 sys.ini .有什么不同? 最佳答案 虽然@Lodder 本质上是正确的 sys.ini文件实际上有 3 个角色。 它
是否可以加载一个自定义的 .ini 文件来覆盖分发包中乱七八糟的 php.ini? 在 unix 系统上,我相信这可以通过在 /etc/php.d 中放置额外的 ini 文件来实现,但我不确定 IIS
如何在另一个 php.ini 文件中包含一个 php.ini 文件? 最佳答案 我认为您不能从主 php.ini 文件中“包含”.ini 文件。 不过,一个可能的解决方案可能是在编译 PHP 时在配置
您好,我有一个代码,其中使用了几个 INI 文件进行预定义设置。我可以在 INI 文件中使用#ifdef 吗?如果可以,我该如何使用它?如果不是,我如何限制我对 INI 文件的代码编译。例如我有一个宏
下面的代码片段可以编辑 ini 文件,但会将所有 ini 条目替换为小写: config = ConfigParser.RawConfigParser() config.read("test.ini"
我按照 this article 中的说明安装并运行 drush :我的服务器是cloudlinux和cagefs.drupal7 Drush 使用全局 php.ini 文件而不是 drish.ini
我是一名优秀的程序员,十分优秀!