Revision 278, 1.4 kB
(checked in by smidl, 15 years ago)
|
props
|
-
Property svn:eol-style set to
native
|
Line | |
---|
1 | /************************************************************************* |
---|
2 | ** Sample3 |
---|
3 | ** Load sample.cfg and try to add a setting "foo".. |
---|
4 | ** on success save to testfoo.cfg |
---|
5 | *************************************************************************/ |
---|
6 | |
---|
7 | #include <iostream> |
---|
8 | #include <libconfig.h++> |
---|
9 | |
---|
10 | using namespace libconfig; |
---|
11 | using namespace std; |
---|
12 | |
---|
13 | /***************************************************************************/ |
---|
14 | |
---|
15 | int main() |
---|
16 | { |
---|
17 | Config cfg; |
---|
18 | try |
---|
19 | { |
---|
20 | /* Load the configuration.. */ |
---|
21 | cout << "loading [sample.cfg]..."; |
---|
22 | cfg.readFile("sample.cfg"); |
---|
23 | cout << "ok" << endl; |
---|
24 | |
---|
25 | /* Add setting "foo" */ |
---|
26 | cout << "add setting \"foo\"/..."; |
---|
27 | Setting &root = cfg.getRoot(); |
---|
28 | Setting &foo = root.add("foo", Setting::TypeInt); |
---|
29 | foo = 1234; |
---|
30 | cout << "ok" << endl; |
---|
31 | |
---|
32 | /** Look up an array element */ |
---|
33 | cout << "looking up array element..."; |
---|
34 | Setting &elem = cfg.lookup("arrays.values.[0]"); |
---|
35 | int val = elem; |
---|
36 | std::cout << "value is: " << val << std::endl; |
---|
37 | std::cout << "path is: " << elem.getPath() << std::endl; |
---|
38 | |
---|
39 | /* Save to "samplefoo.cfg" */ |
---|
40 | cout << "saving [samplefoo.cfg]..."; |
---|
41 | cfg.writeFile("samplefoo.cfg"); |
---|
42 | cout << "ok" << endl; |
---|
43 | |
---|
44 | cout << "Done!" << endl; |
---|
45 | } |
---|
46 | catch (...) |
---|
47 | { |
---|
48 | cout << "failed" << endl; |
---|
49 | } |
---|
50 | |
---|
51 | return 0; |
---|
52 | } |
---|
53 | |
---|
54 | /***************************************************************************/ |
---|