Search code examples
c++configuration-files

C++ lightweight configuration library


I'm looking for a cross-platform C++ lighweight configuration library with non restrictive licence. I need something more complex than standard properties file with sections, but I don't want to use XML (too much writing :-)).

I would like to write configuration this way:

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

Solution

  • There's boost's property_tree. The license allows commercial use.

    Your example:

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

    This can e.g. be exported to JSON

    write_json("my_config.json", pt);
    

    which will then look like

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

    The same way you can export to XML, INI and INFO.