xdgcfg  0.4.1
example.cpp
#include <iostream>
#include <libconfig.h++>
#include "xdgcfg.hpp"
int main()
{
xdgcfg config("test.cfg", // File name.
"xdgcfg"); // Sub directory (optional).
config.set_verbose(true); // Print error messages.
if (config.read() != 0)
{
std::cout << "File not found.\n";
}
// Get a reference to the libconfig::Config object and use it as you would
// normally do.
libconfig::Config &cfg = config.get_cfg();
libconfig::Setting &root = cfg.getRoot();
if (!root.exists("Hello"))
{
root.add("Hello", libconfig::Setting::TypeString) = "World";
}
if (!config.write())
{
std::cerr << "Writing failed.\n";
}
std::cout << "Hello: " << root["Hello"].c_str() << std::endl;
}