An open API service indexing awesome lists of open source software.

https://github.com/ssarcandy/ini-cpp

📑 Yet another ini config parser for modern C++
https://github.com/ssarcandy/ini-cpp

cmake configparser cpp17 gtest header-only ini ini-parser

Last synced: 7 months ago
JSON representation

📑 Yet another ini config parser for modern C++

Awesome Lists containing this project

README

          

# C++ INI Parser

[![C/C++ CI](https://github.com/SSARCandy/ini-cpp/actions/workflows/c-cpp.yml/badge.svg)](https://github.com/SSARCandy/ini-cpp/actions/workflows/c-cpp.yml)
[![codecov](https://codecov.io/gh/SSARCandy/ini-cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/SSARCandy/ini-cpp)

Yet another `.ini` parser for modern c++ (made for cpp17), inspired and extend from [inih](https://github.com/benhoyt/inih).

## Example

The `config.ini`'s content is something looks like:

```
[section1]
any=5

[section2]
any_vec = 1 2 3
```

```cpp
#include "ini/ini.h"

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

// Get and parse the ini value
const auto& v1 = r.Get("section1", "any"); // "5"
const auto& v2 = r.Get("section1", "any"); // 5
const auto& v3 = r.Get("section1", "any"); // 5.0
const auto& v4 = r.GetVector("section2", "any_vec"); // [1.0, 2.0, 3.0]
const auto& v5 = r.GetVector("section2", "any_vec"); // ["1", "2", "3"]

// And also support writing to new ini file.
r.InsertEntry("new_section", "key1", 5); // Create new entry
inih::INIWriter::write("output.ini", r); // Dump ini to file

return 0;
}
```

To learn more, please refer to [test folder](https://github.com/SSARCandy/ini-cpp/tree/master/test), it covered ALL utilities.

## Install

Simply copy the header file `ini/ini.h` to your project, then done.