Skip to content

Commit c4e98b7

Browse files
committed
doc: update example
1 parent 5ddc59c commit c4e98b7

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ Yet another `.ini` parser for modern c++ (made for cpp17), inspired and extend f
1111

1212
```cpp
1313
#include "ini/INIReader.h"
14-
using namespace inih;
1514

1615
int main() {
17-
INIReader r{"./test/fixtures/config.ini"};
18-
19-
const std::string v = r.Get<std::string>("section1", "any"); // "5"
20-
const auto& v1 = r.Get<int>("section1", "any"); // 5
21-
const auto& v2 = r.Get<double>("section1", "any"); // 5.0
22-
23-
const std::vector<float> v3{
24-
r.GetVector<float>("section2", "any_vec")
25-
}; // 1, 2, 3
26-
const std::vector<std::string> v4{
27-
r.GetVector<std::string>("section2", "any_vec")
28-
}; // "1", "2", "3"
16+
inih::INIReader r{"./test/fixtures/config.ini"};
17+
18+
const auto& v1 = r.Get<std::string>("section1", "any"); // "5"
19+
const auto& v2 = r.Get<int>("section1", "any"); // 5
20+
const auto& v3 = r.Get<double>("section1", "any"); // 5.0
21+
const auto& v4 = r.GetVector<float>("section2", "any_vec"); // [1.0, 2.0, 3.0]
22+
const auto& v5 = r.GetVector<std::string>("section2", "any_vec"); // ["1", "2", "3"]
2923

3024
return 0;
3125
}

example.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
#include <iostream>
2-
#include <vector>
32
#include <string>
3+
#include <typeinfo>
4+
#include <boost/core/demangle.hpp>
5+
46
#include "ini/INIReader.h"
57
using namespace inih;
68

9+
namespace bc = boost::core;
10+
711
int main() {
812
INIReader r{"./test/fixtures/config.ini"};
913

10-
const std::string v = r.Get<std::string>("section1", "any");
11-
const auto& v1 = r.Get<int>("section1", "any");
12-
const auto& v2 = r.Get<double>("section1", "any");
14+
const auto& v1 = r.Get<std::string>("section1", "any");
15+
const auto& v2 = r.Get<int>("section1", "any");
16+
const auto& v3 = r.Get<double>("section1", "any");
17+
const auto& v4 = r.GetVector<float>("section2", "any_vec");
18+
const auto& v5{r.GetVector<std::string>("section2", "any_vec")};
19+
20+
/** output
21+
* v1 = "1" type: std::string
22+
* v2 = 1 type: int
23+
* v3 = 1.0 type: double
24+
* v4 = [1, 2, 3] type: std::vector<float>
25+
* v5 = ["1", "2", "3"] type: std::vector<std::string>
26+
*/
1327

14-
const std::vector<float> v3{r.GetVector<float>("section2", "any_vec")};
15-
const std::vector<std::string> v4{r.GetVector<std::string>("section2", "any_vec")};
28+
std::cout << "v1 = " << v1 << ", which is type: " << bc::demangle(typeid(v1).name()) << std::endl;
29+
std::cout << "v2 = " << v2 << ", which is type: " << bc::demangle(typeid(v2).name()) << std::endl;
30+
std::cout << "v3 = " << v3 << ", which is type: " << bc::demangle(typeid(v3).name()) << std::endl;
31+
std::cout << "v4 = "; for (auto& v : v4) std::cout << v << " "; std::cout << ", which is type: " << bc::demangle(typeid(v4).name()) << std::endl;
32+
std::cout << "v5 = "; for (auto& v : v5) std::cout << v << " "; std::cout << ", which is type: " << bc::demangle(typeid(v5).name()) << std::endl;
1633

1734
return 0;
1835
}

0 commit comments

Comments
 (0)