Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/x-rays5/inireader

A simple c++17 header only ini parser/writer.
https://github.com/x-rays5/inireader

cpp cpp17 headeronly ini ini-parser parser

Last synced: 1 day ago
JSON representation

A simple c++17 header only ini parser/writer.

Awesome Lists containing this project

README

        

# inireader
A simple c++17 header only ini parser/writer.

For examples look at the [wiki](https://github.com/X-rays5/inireader/wiki)
# Basic usage

```cpp
#include
#include
#include

/*
config.ini:

foo=bar
[Numbers]
float=3.14
*/

int main() {
ini::Parser ini_file;
try {
ini_file.Parse("config.ini");
ini_file.GetRootSection()["foo"] = "bar";
auto float_val = ini_file["Numbers"]["float"].as();

std::cout << ini_file.GetRootSection()["foo"].as() << " " << float_val << "\n";

ini_file.GetRootSection().Add("foo", "bar");
ini_file.AddSection("Hello World").Add("foo", "bar");

std::ofstream writer("config.ini");
if (writer.is_open())
writer << ini_file.Stringify();
writer.close();
} catch (std::runtime_error& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}
```
# CMake usage
```cmake
cmake_minimum_required(VERSION 3.24)
project(example)

set(CMAKE_CXX_STANDARD 17)

add_subdirectory(inireader)

add_executable(${PROJECT_NAME} main.cpp)

# Include the inireader headers via the cmake INTERFACE library API.
target_link_libraries(${PROJECT_NAME} PRIVATE inireader::inireader)

```