当前位置: 首页 > article >正文

读取ini配置文件----c++

使用boost库读取ini配置文件

#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/ini_parser.hpp"

/// 读取ini配置文件数据
bool readIni(const std::string iniPath)
{
    try {
        boost::property_tree::ptree pt;
        // 使用 ini_parser 解析 INI 文件
        boost::property_tree::ini_parser::read_ini(iniPath, pt);

        // 读取配置项并输出
        int outdate_hour = pt.get<int>("PPTN.outdate_hour");
        std::string orm_warn_str = pt.get<std::string>("PPTN.warn_orm");
        std::string orm_data_str = pt.get<std::string>("PPTN.data_orm");
        std::string task_id = pt.get<std::string>("task.task_id");
        std::string clock_svr_addr = pt.get<std::string>("clock.svr_addr");
        int flood_retry = pt.get<int>("PPTN.flood_retry");
        int running_mode = pt.get<int>("PPTN.warn_method");
        int running_interval = pt.get<int>("PPTN.running_interval");
        int warning_rule_method = pt.get<int>("PPTN.warn_rule_method");
        std::string addr = pt.get<std::string>("publish.pub_addr");
        std::string port = pt.get<std::string>("publish.pub_port");
        std::string redispwd = pt.get<std::string>("publish.pub_pwd");

        
    }
    catch (boost::property_tree::ptree_error& e) {
        std::cerr << "Error: " << e.what() << std::endl;
    }

    return true;
}

int main()
{
    std::string inipath = "./form.ini";

    readIni(inipath);
    
    return 0;
}

配置文件内容为

[clock]
svr_addr = 192.168.0.181:8081
[task]
task_id = 54476284

[publish]
# redis: 0; kafka : 1
pub_type = 0
pub_addr = 192.168.0.180
pub_port = 8080
pub_pwd = 123
pub_channel = warning_added,warning_status_changed

[PPTN]
# 1 通过加权平均   2 通过与关联站的最大值比价
warn_rule_method = 1
warn_method = 2
flood_retry = 0
running_interval = 10
outdate_hour= 2
warn_orm = mssql
data_orm = oracle

http://www.kler.cn/a/152542.html

相关文章:

  • arm-eabi-gcc 和 arm-none-eabi-gcc 都是基于 GCC 的交叉编译器
  • 【android开发-01】android中toast的用法介绍
  • web项目添加防调试
  • 腾讯云年末感恩回馈:2核2G4M云服务器118元1年,新老用户同享!
  • Node——npm包管理器的使用
  • C语言-指针讲解(4)
  • 记一次Kotlin Visibility Modifiers引发的问题
  • 【EasyExcel】导出excel并支持自定义设置数据行背景颜色等
  • 【ASP.NET CORE】EntityFrameworkCore 数据迁移
  • 键盘打字盲打练习系列之刻意练习——1
  • ssm+java车辆售后维护系统 springboot汽车保养养护管理系统+jsp
  • 不会代码(零基础)学语音开发(学习工具)
  • 物联网实训室虚拟仿真软件建设方案
  • 代码随想录刷题题Day2
  • 【PUSDN】WebStorm中报错Switch language version to React JSX
  • 可验证随机函数(VRF)
  • 百度推送收录工具-免费的各大搜索引擎推送工具
  • 如何在服务器上运行python文件
  • 二叉树题目:祖父结点值为偶数的结点和
  • Android设置文字颜色渐变