-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
39 lines (30 loc) · 1.1 KB
/
Copy pathexample.cpp
File metadata and controls
39 lines (30 loc) · 1.1 KB
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
#include <cstdlib>
#include <iostream>
#include "ConfigParser.h"
int main (int argc, char *argv[])
{
// You could also change the delim and comment character here
ConfigParser config("config.cfg");
int foo = config.getInt("foo").second;
std::string bar = config.getString("bar").second;
std::pair<bool, double> pi = config.getDouble("pi");
// If optional flag is set it will produce no error
auto notExisting = config.getString("notExisting", true);
// Check if key was found in config file
if (!notExisting.first)
{
std::cerr << "Optional key not found in config!" << std::endl;
}
// You can also use a fallback value in case of an not existing key
std::string fallback = config.getString("notExisting", std::string("fallback")).second;
if(config.hasErrors())
{
std::cerr << "ERROR: Configuration incomplete!" << std::endl;
return EXIT_FAILURE;
}
std::cout << bar << std::endl;
std::cout << foo << std::endl;
std::cout << pi.second << std::endl;
std::cout << fallback << std::endl;
return EXIT_SUCCESS;
}