【问题标题】:Boost property tree with INI files使用 INI 文件提升属性树
【发布时间】:2021-03-25 15:19:03
【问题描述】:

我正在使用 Boost 属性树类来读取和写入 MS Ini 文件。其中一个部分名称包含一个文字点作为字符串的一部分。没有等级制度。如何引用这个点?

[system-no.1]
acq=3

【问题讨论】:

    标签: c++ boost


    【解决方案1】:

    您只能通过使用替代分隔符创建路径:

    Live on Coliru

    #include <boost/property_tree/ini_parser.hpp>
    #include <iostream>
    using boost::property_tree::ptree;
    
    int main() {
        ptree::path_type path("system=no.1#acq", '#');
    
        ptree pt;
        pt.put(path, 3);
    
        write_ini(std::cout, pt);
    }
    

    打印

    [system=no.1]
    acq=3
    

    奖金

    由于构造函数不明确,您可以缩写为:

    pt.put({"system=no.1#acq", '#'}, 3);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 2013-05-16
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多