1

it seems I am unable to find any source telling me how to use lists with libconfig.

Let's say my config file looks like this:

Layer1 = {
    Layer2 = {
        SomeOption = "MyValue";
        Options =  (
            {
                Option = "Full Screen";
                Value = "No";
            },
            {
                Option = "Title";
                Value = "Test";
            }
        );
    };
};

How can I read Options with libconfig++ ? I can only find methods for reading single values.

timrau
  • 22,578
  • 4
  • 51
  • 64
Maru
  • 894
  • 1
  • 12
  • 29

1 Answers1

3

OK, I have found the answer:

using namespace libconfig;

// ...

Config *pConfig = new Config();
// ...
Setting& settings = pConfig->lookup("Layer1.Layer2.Options");
const char* op0 = settings[0]["Option"];

// ...
n00dle
  • 5,949
  • 2
  • 35
  • 48
Maru
  • 894
  • 1
  • 12
  • 29
  • Hi, I'm looking at a problem like yours and wonder about your solution. To get the data from the list one is first to lookup the list into a settings and then parse out using name- value pair. But what if I have a list like this Options = (1, 3, 6, 8, 0, 4,); Does the same solution work only with "settings[0][2]" to index out the list data? Is it the same solution for arrays? – Anders S May 16 '19 at 07:04