Revision 278, 1.0 kB
(checked in by smidl, 15 years ago)
|
props
|
-
Property svn:eol-style set to
native
|
Line | |
---|
1 | /************************************************************************* |
---|
2 | ** Sample1 |
---|
3 | ** Load sample.cfg and increment the "X" setting |
---|
4 | *************************************************************************/ |
---|
5 | |
---|
6 | #include <iostream> |
---|
7 | #include <libconfig.h++> |
---|
8 | |
---|
9 | using namespace libconfig; |
---|
10 | using namespace std; |
---|
11 | |
---|
12 | /***************************************************************************/ |
---|
13 | |
---|
14 | int main() |
---|
15 | { |
---|
16 | Config cfg; |
---|
17 | |
---|
18 | try |
---|
19 | { |
---|
20 | /* Load the configuration.. */ |
---|
21 | cout << "loading [sample.cfg].."; |
---|
22 | cfg.readFile("sample.cfg"); |
---|
23 | cout << "ok" << endl; |
---|
24 | |
---|
25 | /* Increment "x" */ |
---|
26 | cout << "increment \"x\".."; |
---|
27 | Setting& s = cfg.lookup("x"); |
---|
28 | long x = s; |
---|
29 | s = ++x; |
---|
30 | cout << "ok (x=" << x << ")" << endl; |
---|
31 | |
---|
32 | // Save the configuration |
---|
33 | cout << "saving [sample.cfg].."; |
---|
34 | cfg.writeFile("sample.cfg"); |
---|
35 | cout << "ok" << endl; |
---|
36 | |
---|
37 | cout << "Done!" << endl; |
---|
38 | } |
---|
39 | catch (...) |
---|
40 | { |
---|
41 | cout << "failed" << endl; |
---|
42 | } |
---|
43 | |
---|
44 | return 0; |
---|
45 | } |
---|
46 | |
---|
47 | /***************************************************************************/ |
---|