ini-cpp
C++ INI Parser

C/C++ CI Build Status 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;
}
Definition: ini.h:200
const std::unordered_map< std::string, std::string > Get(std::string section) const
Get the map representing the values in a section of the INI file.
Definition: ini.h:350
static void write(const std::string &filepath, const INIReader &reader)
Write the contents of an INI file to a new file.
Definition: ini.h:604

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.