-
Notifications
You must be signed in to change notification settings - Fork 94
/
INIReaderTest.cpp
32 lines (28 loc) · 1.03 KB
/
INIReaderTest.cpp
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
// Example that shows simple usage of the INIReader class
#include "INIReader.h"
#include <iostream>
#include <sstream>
std::string sections(INIReader &reader) {
std::stringstream ss;
std::set<std::string> sections = reader.Sections();
for (std::set<std::string>::iterator it = sections.begin();
it != sections.end(); ++it)
ss << *it << ",";
return ss.str();
}
int main() {
INIReader reader("test.ini");
if (reader.ParseError() < 0) {
std::cout << "Can't load 'test.ini'\n";
return 1;
}
std::cout << "Config loaded from 'test.ini': found sections="
<< sections(reader)
<< " version=" << reader.GetInteger("protocol", "version", -1)
<< ", name=" << reader.Get("user", "name", "UNKNOWN")
<< ", email=" << reader.Get("user", "email", "UNKNOWN")
<< ", multi=" << reader.Get("user", "multi", "UNKNOWN")
<< ", pi=" << reader.GetReal("user", "pi", -1)
<< ", active=" << reader.GetBoolean("user", "active", true) << "\n";
return 0;
}