libconfig read list C

1.4k Views Asked by At

I'm trying to read this example of configuration with libconfig library in C, but don't see any example of reading a list and store it...

sound = {
         string_length = 50;
         sound_folder = "./bin/sound/";
         sounds_number = 4;
         sounds_list = ( "001_piano.wav", "voz4408.wav", "001_bajo.wav", "001_bateriabuena.wav" );
};

I what to know if there is a way to load a list like the sounds_list. And don't create a structure like the way I have it now:

 sounds_list = ( { file_name = "001_piano.wav";},
         { file_name = "voz4408.wav";},
         { file_name = "001_bajo.wav";},
         { file_name = "001_bateriabuena.wav";}
  );
1

There are 1 best solutions below

0
On BEST ANSWER

you can use the structure as followed:

test_array = ["aaa", "bbb", "ccc"];

when you want to parse the parameter above, you can use the code as followed:

libconfig::Config cfg;
cfg.readFile(conf_file.c_str());
const Setting &test_array = cfg.lookup("test_array");
int count = test_array.getLength();
for (int i = 0; i < count; ++i) {
    std::cout << test_array[i] << std::endl;
}

you can also refer libconfig_manual for more information