aboutsummaryrefslogtreecommitdiffstats
path: root/samples/c++/sample2.cpp
blob: defceb8c2972eefd4991b380abf4d7013ee9e962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}


/***************************************************************************/