Skip to content

📑 Yet another ini config parser for modern C++

License

Notifications You must be signed in to change notification settings

SSARCandy/ini-cpp

Repository files navigation

C++ INI Parser

C/C++ CI codecov

Yet another .ini parser for modern c++ (made for cpp17), inspired and extend from inih.

Example

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

[section1]
any=5

[section2]
any_vec = 1 2 3
#include "ini/ini.h"

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

    // Get and parse the ini value
    const auto& v1 = r.Get<std::string>("section1", "any"); // "5"
    const auto& v2 = r.Get<int>("section1", "any"); // 5
    const auto& v3 = r.Get<double>("section1", "any"); // 5.0
    const auto& v4 = r.GetVector<float>("section2", "any_vec"); // [1.0, 2.0, 3.0]
    const auto& v5 = r.GetVector<std::string>("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, it covered ALL utilities.

Install

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