An example of how to use the Config class
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
if (!cfg.
open(
"test.cfg"))
{
cerr << "*** Error: Could not open config file test.cfg\n";
exit(1);
}
cout <<
"value=" << cfg.
getValue(
"SECTION1",
"VALUE1") << endl;
string str_val;
if (cfg.
getValue(
"SECTION1",
"VALUE2", str_val))
{
cout << "str_val=" << str_val << endl;
}
else
{
cerr << "*** ERROR: Config variable SECTION1/VALUE2 not found.\n";
}
int int_val = 0;
if (cfg.
getValue(
"SECTION2",
"MY_INT", int_val))
{
cout << "int_val=" << int_val << endl;
}
else
{
cerr << "*** ERROR: Config variable SECTION2/MY_INT malformed or "
"not found.\n";
}
char char_val = 'Q';
if (cfg.
getValue(
"SECTION1",
"NO_VALUE", char_val,
true))
{
cout << "char_val=" << char_val << endl;
}
else
{
cerr << "*** ERROR: Config variable SECTION1/NO_VALUE malformed.\n";
}
float float_val = 0.0;
if (cfg.
getValue(
"SECTION2",
"MY_FLOAT", 3.0f, 4.0f, float_val))
{
cout << "float_val=" << float_val << endl;
}
else
{
cerr << "*** ERROR: Config variable SECTION2/MY_FLOAT malformed, "
"not found or out of range.\n";
}
}