inih

by jtilly

jtilly / inih

This is a header only C++ version of inih.

264 Stars 71 Forks Last release: Not found Other 84 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

inih

Build Status

This is a header only C++ version of inih.

inih (INI Not Invented Here) is a simple .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 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
):
#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:

g++ INIReaderTest.cpp -o INIReaderTest.out
./INIReaderTest.out
# Config loaded from 'test.ini': version=6, name=Bob Smith, [email protected], pi=3.14159, active=1

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.