Cross-platform C++ library providing a simple API to read and write INI-style configuration files
Cross-platform C++ library providing a simple API to read and write INI-style configuration files
A cross-platform library that provides a simple API to read and write INI-style configuration files. It supports data files in ASCII, MBCS and Unicode. It is designed explicitly to be portable to any platform and has been tested on Windows, WinCE and Linux. Released as open-source and free using the MIT licence.
Full documentation of the interface is available in doxygen format. See latest documentation here.
SimpleIni is a header-only library. No building is required to use it in your project.
Simply include SimpleIni.h in your source files:
#include "SimpleIni.h"That's it! The library is ready to use.
While the library itself doesn't require building, you can build and run the test suite using CMake. A top-level Makefile wraps the usual CMake workflow for local development:
make help # list targets
make check # format-check, build, and test
make format # apply clang-format
make format-check # verify formatting
make test # run ctest
make clean # remove build/Requires cmake, a C++17 compiler, and clang-format for format targets. Test builds use -Werror. CMake remains the build system.
CI (.github/workflows/build-and-test.yml) runs make format-check on Linux only; tests run on Linux (x64 and arm64), Windows, macOS, and FreeBSD (14.4 via a VM on ubuntu-latest, currently disabled).
Direct CMake usage:
# Configure the project
cmake -S . -B build
# Build the tests (optional)
cmake --build build
# To build without tests
cmake -S . -B build -DBUILD_TESTING=OFF
cmake --build build
# Run all tests
cd build
ctest --verboseTo use SimpleIni in your CMake project:
# Add SimpleIni as a subdirectory
add_subdirectory(simpleini)
# Link against your target
target_link_libraries(your_target PRIVATE SimpleIni::SimpleIni)Or install it system-wide:
cmake -S . -B build
cmake --build build
sudo cmake --install buildThen in your CMake project:
find_package(SimpleIni REQUIRED)
target_link_libraries(your_target PRIVATE SimpleIni::SimpleIni)Note that SI_CONVERT_GENERIC is not the default conversion mode. When enabled,
UTF-8 conversion is built into the header; no additional source files are required.
Earlier releases shipped ConvertUTF.c and ConvertUTF.h for SI_CONVERT_GENERIC
and expected you to compile them into your project. UTF-8 conversion is now inline
in SimpleIni.h. Remove any ConvertUTF.c / ConvertUTF.h from your build and
drop links to ConvertUTF.c; no replacement source files are required.
These snippets are included with the distribution in the automatic tests as ts-snippets.cpp.
// simple demonstration
CSimpleIniA ini;
ini.SetUnicode();
SI_Error rc = ini.LoadFile("example.ini");
if (rc pItem);
}… // deleting a key from a section. Optionally the entire
// section may be deleted if it is now empty.
bool done, deleteSectionIfEmpty = true;
done = ini.Delete("section1", "key1", deleteSectionIfEmpty);
ASSERT_EQ(done, true);
done = ini.Delete("section1", "key1");
ASSERT_EQ(done, false);
// deleting an entire section and all keys in it
done = ini.Delete("section2", nullptr);
ASSERT_EQ(done, true);
done = ini.Delete("section2", nullptr);
ASSERT_EQ(done, false); // save the data to a string
std::string data;
rc = ini.Save(data);
if (rc < 0) { /* handle error */ };
ASSERT_EQ(rc, SI_OK);
// save the data back to the file
rc = ini.SaveFile("example2.ini");
if (rc < 0) { /* handle error */ };
ASSERT_EQ(rc, SI_OK);No open issues yet, or sync has not completed.