-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinifile_read.cpp
More file actions
51 lines (45 loc) · 1.29 KB
/
inifile_read.cpp
File metadata and controls
51 lines (45 loc) · 1.29 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
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Sample: read_from_stream
* ------------------------
* Reads INI data from a string stream and prints all sections and key-value pairs.
*
* 示例:read_from_stream
* ------------------------
* 从字符串流读取 INI 数据,并打印所有 section 及其键值对内容。
*/
#include <inifile/inifile.h>
int main()
{
const char *str = R"(
[Section]
key=value
hello=world
num=123
[Nothing1]
[Test]
status=pass
[Nothing2]
)";
// Read ini data from stream
std::istringstream is(str);
ini::inifile inif;
inif.read(is);
//// Read ini data from string
// ini::inifile inif;
// inif.from_string(str);
std::cout << "~~~~~~~~~~~~~~~~~read ini contents~~~~~~~~~~~~~~~~~\n";
std::cout << "inifile has " << inif.size() << " sections\n";
for (const auto &sec_pair : inif)
{
const std::string §ion_name = sec_pair.first;
const ini::section §ion = sec_pair.second;
std::cout << " section '" << section_name << "' has " << section.size() << " key-values.\n";
for (const auto &kv : section)
{
const std::string &key = kv.first;
const auto &value = kv.second;
std::cout << " kv: '" << key << "' = '" << value << "'\n";
}
}
std::cout << "~~~~~~~~~~~~~~~~~read ini contents~~~~~~~~~~~~~~~~~\n";
}