User Tools

Site Tools


Libconfig sample

as snippet.

config1.cpp
/*
 * config1.cpp
 *
 * Author, Copyright: Oleg Borodin <onborodin@gmail.com>
 */
 
 
#include <iostream>
#include <libconfig.hpp>
 
int main(int argc, char **argv) {
 
    libconfig::Config config;
 
    try {
        config.readFile("test.conf");
    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
        return 1;
    }
 
    std::string foo = config.lookup("foo");
    std::cout << foo << std::endl;
 
    try {
        libconfig::Setting &setting = config.lookup("");
        int n = setting["list"][2];
        std::cout << n << std::endl;
    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
        return 1;
    }
 
    return 0;
}

Out

$ cat test.conf
foo = "bar";
list = (1, 2, 4);

$ ./config1
bar
4

First PagePrevious PageBack to overviewNext PageLast Page