-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinifile_write.cpp
More file actions
55 lines (46 loc) · 1.73 KB
/
inifile_write.cpp
File metadata and controls
55 lines (46 loc) · 1.73 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
52
53
54
55
/*
* Sample: write_and_serialize_ini
* -------------------------------
* Demonstrates writing various typed key-value pairs and comments into an INI structure,
* then serializing the INI data to a string stream for output.
*
* 示例:写入并序列化 INI 文件
* -------------------------------
* 演示如何写入不同类型的键值对和注释到 INI 结构中,
* 并将 INI 数据序列化到字符串流以便输出。
*/
#include <inifile/inifile.h>
int main()
{
ini::inifile inif;
inif["section1"]["string"] = "value";
inif["section1"]["int"] = 123;
inif["section1"]["float"] = 3.14F;
inif["section1"]["double"] = 3.141592;
inif["section1"]["char"] = 'c';
inif["section1"]["bool"] = true;
inif["section1"].set_comment("Comments on section1");
inif.set("section2", "int", 99);
inif.set("section2", "bool", false);
inif.set("section2", "double", 1.67);
inif.set("section2", "string", "abcdef");
inif.at("section2").add_comment("Comments on section2");
inif["section3"].set("int", 100);
inif["section3"].set("bool", true);
inif["section3"].set("float", 0.99);
inif["section3"].set("string", std::string("inifile"));
inif["section4"].set({{"bool", true},
{"int", 123},
{"double", 999.888},
{"string", "ABC"},
{"char", 'm'}});
// Write ini data to stream
std::ostringstream ss;
inif.write(ss);
std::string content = ss.str();
//// ini data to string
// std::string content = inif.to_string();
std::cout << "~~~~~~~~~~~~~~~~~write inifile contents~~~~~~~~~~~~~~~~~\n";
std::cout << content << '\n';
std::cout << "~~~~~~~~~~~~~~~~~write inifile contents~~~~~~~~~~~~~~~~~\n";
}