aboutsummaryrefslogtreecommitdiffstats
path: root/samples/c++/sample2.cpp
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2011-12-01 22:54:16 +0000
committerJonathan McCrohan <jmccrohan@gmail.com>2011-12-01 22:54:16 +0000
commit58bf1382be0cbcf3f9649286fd2719b789a1595f (patch)
treeb73665275a2d44879a8230c913b1ef21a42e57da /samples/c++/sample2.cpp
downloadlibconfig-58bf1382be0cbcf3f9649286fd2719b789a1595f.tar.gz
Imported Upstream version 1.3.2upstream/1.3.2
Diffstat (limited to '')
-rw-r--r--samples/c++/sample2.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/samples/c++/sample2.cpp b/samples/c++/sample2.cpp
new file mode 100644
index 0000000..defceb8
--- /dev/null
+++ b/samples/c++/sample2.cpp
@@ -0,0 +1,43 @@
+/*************************************************************************
+ ** Sample2
+ ** Load sample.cfg and access the "values" array
+ *************************************************************************/
+
+#include <iostream>
+#include <libconfig.h++>
+
+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;
+
+ // Display the "values" array
+ cout << "display the \"values\" array..";
+ Setting& s = cfg.lookup("values");
+ long value1 = s[0];
+ long value2 = s[1];
+ cout << "[" << value1 << "," << value2 << "]..";
+ cout << "ok" << endl;
+
+ cout << "Done!" << endl;
+ }
+ catch (...)
+ {
+ cout << "failed" << endl;
+ }
+
+ return 0;
+}
+
+
+/***************************************************************************/