c++ - C ++ / Boost :: Propery_Tree - 是否可以使用名称中的点来获取ini配置值
问题描述
这是我的代码:
我的Config.h
:
#include <string>
#include <boost/property_tree/ini_parser.hpp>
namespace pt = boost::property_tree;
class Config {
public:
Config(std::string conf);
template<typename T>
T GetConfigValue(std::string configKey, T value = 0){
pt::ptree tree;
pt::read_ini(_configFile, tree);
return tree.get<T>(configKey, value);
}
private:
std::string _configFile;
};
我是这样称呼它的:
#include "Logger.h"
#include "Config.h"
int main() {
Config * config = new Config("/WorldServer.conf.dist");
std::string def = "Nothing there.";
Logger::Log(config->GetConfigValue("WorldServer.MaxPingTime", def));
}
以下是 的内容WorldServer.conf.dist
:
[WorldServer]
MaxPingTime = 30
MySQL.User = "root"
当我执行
Logger::Log(config->GetConfigValue("WorldServer.MaxPingTime", def));
我看到30
结果是正确的,但是当我执行时:
Logger::Log(config->GetConfigValue("WorldServer.MySQL.User", def));
我看到了结果Nothing there.
据我了解.
是MySQL.User
导致问题的原因。
我的问题是我可以使用 boost 属性树以某种方式使其与 dot 一起使用来解析 ini 配置吗?
解决方案
推荐阅读
- laravel - 在 laravel 中使用 group by 时获取数据并忽略空值
- docker - 无法通过用户定义的网络名称从另一个容器访问容器
- swiftui - .onDrop 在 SwiftUI 的表单和部分中的视图中不起作用
- mysql - 是一个分区表更好的响应时间还是多个表,用于网站和操作(插入,更新,删除)经常使用
- reactjs - React 表头未与表体正确对齐
- methods - getter 和 setter 方法是什么?
- java - 检查 Firestore 集合元素是否存在
- javascript - 将值从雪花中的另一个表插入临时表的存储过程
- google-apps-script - 如何从 Google 表格中人名的多个实例创建单个 PDF?
- amazon-redshift - ETL 与 Talend + AWS Redshift?