forked from wangqiongSE/yazi-ini
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (43 loc) · 1.24 KB
/
Copy pathmain.cpp
File metadata and controls
58 lines (43 loc) · 1.24 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
56
57
58
#include <iostream>
using namespace std;
#include "IniFile.h"
using namespace yazi::utility;
int main()
{
// load ini file
const string & filename = "./main.ini";
IniFile ini(filename);
// show the ini file
ini.show();
// dump the ini file
ini.save("./main2.ini");
// get value
const string & name = ini["profile"]["name"];
std::cout << "ini[\"profile\"][\"name\"] = " << name << std::endl;
// get value
int age = ini.get("profile", "age");
std::cout << "ini[\"profile\"][\"age\"] = " << age << std::endl;
// set value
ini["profile"]["age"] = 31;
// set value
ini.set("profile", "age", 32);
age = ini["profile"]["age"];
std::cout << "int[\"profile\"][\"age\"] = " << age << std::endl;
// if the server section is exist
if (ini.has("server"))
{
std::cout << "ini[\"server\"] is exist" << std::endl;
}
// if the server section and ip key is exist
if (ini.has("server", "ip"))
{
std::cout << "ini[\"server\"][\"ip\"] is exist" << std::endl;
}
// remove the key ip in server section
ini.remove("server", "ip");
// remove the sever section
ini.remove("server");
// clear the ini file
ini.clear();
return 0;
}