tastytea
2fb329a302
Some checks failed
continuous-integration/drone/push Build is failing
* Compile a library again. * Made CMake recipes modular. * Added xdgcfgConfig.cmake. * Added pkg-config file. * Updated readme.
33 lines
783 B
C++
33 lines
783 B
C++
#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;
|
|
}
|