C ++轻量级配置库

时间:2012-02-12 10:54:47

标签: c++ configuration-files

我正在寻找具有非限制性许可证的跨平台C ++轻量级配置库。我需要比标准属性文件更复杂的部分,但是我不想使用XML(写得太多了: - ))。

我想用这种方式编写配置:

render = 
{
    window = 
    {
        width = 800,
        height = 600
    }
}

2 个答案:

答案 0 :(得分:14)

有提升property_treelicense允许商业用途。

你的例子:

ptree pt;
pt.put("render.window.width", 800);
pt.put("render.window.height", 600);

这可以是例如导出为JSON

write_json("my_config.json", pt);

然后看起来像

{
  "render":
  {
    "window":
    {
      "width": 800;
      "height": 600;
    }
  }
}

与导出到XML,INI和INFO的方式相同。

答案 1 :(得分:5)

您也可以尝试JsonCpp并在Json中编写配置文件,其语法与您喜欢的语法非常相似:

// Configuration options
{
    // Default encoding for text
    "encoding" : "UTF-8",

    // Plug-ins loaded at start-up
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],

    // Tab indent size
    "indent" : { "length" : 3, "use_space": true }
}

MIT License之下,所以它非常宽松。

相关问题