Skip to content

A C++20 library for reading and writing INI files

License

Notifications You must be signed in to change notification settings

Master92/cppIni

Repository files navigation

cppIni - A C++20 library for reading and writing INI files

Branch Status Coverage
master Build codecov
develop Build codecov

Release License GitHub stars

Features

This project is a library for reading and writing INI files. It is written in C++20 and uses the STL. It is tested with GCC 13, Clang 16 and MSVC 19.36. It should work with any compiler that supports C++20.

Reading and manipulating INI files

The library is able to read INI files and parses them automatically. It is able to read the following types:

  • bool
  • char
  • short
  • int
  • long
  • long long
  • unsigned char
  • unsigned short
  • unsigned int
  • unsigned long
  • unsigned long long
  • float
  • double
  • long double
  • std::string
  • std::string_view
  • const char*

Accessing a value is done with the get template-function. It takes the section and the key as parameters and returns the value as the specified type T. If the value does not exist, the default value (T()) is returned.

Setting a value is done with the set template-function. It takes the section, the key and the value as parameters. The value is converted to a string and written to the file. If the section or the key does not exist, it is created. On every write, the file is completely rewritten.

Usage

C++:

#include <cppIni/cppIni.hpp>

File ini("test.ini");
const auto intValue = ini.get<int>("section", "key");
const auto newValue = 42;
ini.set("section", "key", newValue);

C:

#include <cppIni/cppIni_c.h>

void* ini = cppIni_open("test.ini");
const int intValue = cppIni_geti(ini, "section", "key");
const int newValue = 42;
cppIni_set(ini, "section", "key", newValue);
cppIni_close(&ini);

License

cppIni is licensed under the GPLv3. See COPYING for more information.