From 58bf1382be0cbcf3f9649286fd2719b789a1595f Mon Sep 17 00:00:00 2001 From: Jonathan McCrohan Date: Thu, 1 Dec 2011 22:54:16 +0000 Subject: Imported Upstream version 1.3.2 --- samples/c++/sample1.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 samples/c++/sample1.cpp (limited to 'samples/c++/sample1.cpp') diff --git a/samples/c++/sample1.cpp b/samples/c++/sample1.cpp new file mode 100644 index 0000000..7344838 --- /dev/null +++ b/samples/c++/sample1.cpp @@ -0,0 +1,47 @@ +/************************************************************************* + ** Sample1 + ** Load sample.cfg and increment the "X" setting + *************************************************************************/ + +#include +#include + +using namespace libconfig; +using namespace std; + +/***************************************************************************/ + +int main() +{ + Config cfg; + + try + { + /* Load the configuration.. */ + cout << "loading [sample.cfg].."; + cfg.readFile("sample.cfg"); + cout << "ok" << endl; + + /* Increment "x" */ + cout << "increment \"x\".."; + Setting& s = cfg.lookup("x"); + long x = s; + s = ++x; + cout << "ok (x=" << x << ")" << endl; + + // Save the configuration + cout << "saving [sample.cfg].."; + cfg.writeFile("sample.cfg"); + cout << "ok" << endl; + + cout << "Done!" << endl; + } + catch (...) + { + cout << "failed" << endl; + } + + return 0; +} + +/***************************************************************************/ -- cgit v1.2.3