https://github.com/jtilly/inih
This is a header only C++ version of inih.
https://github.com/jtilly/inih
Last synced: 7 months ago
JSON representation
This is a header only C++ version of inih.
- Host: GitHub
- URL: https://github.com/jtilly/inih
- Owner: jtilly
- License: other
- Created: 2016-01-18T19:16:20.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-09-18T13:41:38.000Z (about 1 year ago)
- Last Synced: 2025-04-02T04:02:10.725Z (8 months ago)
- Language: C++
- Homepage: https://github.com/benhoyt/inih
- Size: 72.3 KB
- Stars: 445
- Watchers: 19
- Forks: 95
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- fucking-awesome-cpp - inih - Single header only C++ version of <b><code> 2850⭐</code></b> <b><code> 546🍴</code></b> [inih](https://github.com/benhoyt/inih)). [BSD-3-Clause] (Configuration)
- awesome-cpp-cn - inih
- awesome-hpp - inih - BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) | (Data Formats)
- awesome-cpp - inih - Single header only C++ version of [inih](https://github.com/benhoyt/inih). [BSD-3-Clause] (Configuration)
README
# inih
[](https://github.com/jtilly/inih/actions/workflows/ci.yml)
This is a header only C++ version of [inih](https://github.com/benhoyt/inih).
**inih (INI Not Invented Here)** is a simple [.INI file](http://en.wikipedia.org/wiki/INI_file) parser written in C. It's only a couple of pages of code, and it was designed to be _small and simple_, so it's good for embedded systems. It's also more or less compatible with Python's [ConfigParser](http://docs.python.org/library/configparser.html) style of .INI files, including RFC 822-style multi-line syntax and `name: value` entries.
## Usage
All you need to do is to include `INIReader.h`. Consider the following example (`INIReaderTest.cpp`):
```cpp
#include
#include "INIReader.h"
int main() {
INIReader reader("test.ini");
if (reader.ParseError() != 0) {
std::cout << "Can't load 'test.ini'\n";
return 1;
}
std::cout << "Config loaded from 'test.ini': version="
<< reader.GetInteger("protocol", "version", -1) << ", name="
<< reader.Get("user", "name", "UNKNOWN") << ", email="
<< reader.Get("user", "email", "UNKNOWN") << ", pi="
<< reader.GetReal("user", "pi", -1) << ", active="
<< reader.GetBoolean("user", "active", true) << "\n";
return 0;
}
```
To compile and run:
```sh
g++ INIReaderTest.cpp -o INIReaderTest.out
./INIReaderTest.out
# Config loaded from 'test.ini': version=6, name=Bob Smith, email=bob@smith.com, pi=3.14159, active=1
```