Skip to content

Commit 5d5d18e

Browse files
committed
doc: update readme and example
1 parent e3d9398 commit 5d5d18e

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,39 @@ Yet another `.ini` parser for modern c++ (made for cpp17), inspired and extend f
99

1010
## Example
1111

12+
The `config.ini`'s content is something looks like:
13+
14+
```
15+
[section1]
16+
any=5
17+
18+
[section2]
19+
any_vec = 1 2 3
20+
```
21+
1222
```cpp
13-
#include "ini/INIReader.h"
23+
#include "ini/ini.h"
1424

1525
int main() {
1626
inih::INIReader r{"./test/fixtures/config.ini"};
1727

28+
// Get and parse the ini value
1829
const auto& v1 = r.Get<std::string>("section1", "any"); // "5"
1930
const auto& v2 = r.Get<int>("section1", "any"); // 5
2031
const auto& v3 = r.Get<double>("section1", "any"); // 5.0
2132
const auto& v4 = r.GetVector<float>("section2", "any_vec"); // [1.0, 2.0, 3.0]
2233
const auto& v5 = r.GetVector<std::string>("section2", "any_vec"); // ["1", "2", "3"]
2334

35+
// And also support writing to new ini file.
36+
r.InsertEntry("new_section", "key1", 5); // section and key not exist
37+
inih::INIWriter::write("output.ini", r); // Dump ini to file
38+
2439
return 0;
2540
}
2641
```
2742

28-
The `config.ini`'s content is something looks like:
29-
30-
```
31-
[section1]
32-
any=5
33-
34-
[section2]
35-
any_vec = 1 2 3
36-
```
37-
3843
To learn more, please refer to [test folder](https://github.com/SSARCandy/ini-cpp/tree/master/test), it covered ALL utilities.
3944

4045
## Install
4146

42-
Simply copy the header file `ini/INIReader.h` to your project, then done.
47+
Simply copy the header file `ini/ini.h` to your project, then done.

example.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <typeinfo>
44
#include <boost/core/demangle.hpp>
55

6-
#include "ini/INIReader.h"
6+
#include "ini/ini.h"
77
using namespace inih;
88

99
namespace bc = boost::core;
@@ -31,5 +31,14 @@ int main() {
3131
std::cout << "v4 = "; for (auto& v : v4) std::cout << v << " "; std::cout << ", which is type: " << bc::demangle(typeid(v4).name()) << std::endl;
3232
std::cout << "v5 = "; for (auto& v : v5) std::cout << v << " "; std::cout << ", which is type: " << bc::demangle(typeid(v5).name()) << std::endl;
3333

34+
// section exist, key not exist
35+
r.InsertEntry("section1", "my_custom_key", "hello world");
36+
37+
// section&key not exist
38+
r.InsertEntry("new_section", "key1", 5);
39+
40+
// Dump ini to file
41+
INIWriter::write("output.ini", r);
42+
3443
return 0;
3544
}

0 commit comments

Comments
 (0)