90th / iniParser

lightweight C++ library for parsing and manipulating INI (Initialization) files. INI files are simple text files that store configuration data in a key-value pair format, organized into sections.
MIT License
10 stars 1 forks source link
cpp ini-parser ini-reader ini-writer inifile initialization library lightweight

Lightweight C++ INI Parser

This is a lightweight C++ library for parsing and manipulating INI (Initialization) files. INI files are simple text files that store configuration data in a key-value pair format, organized into sections.

Features

Usage

  1. Include the IniParser.h header file in your C++ project.
  2. Instantiate an IniParser object.
  3. Use the provided methods to parse, manipulate, and save INI files.
#include "IniParser.h"
#include <iostream>

int main() {
    // Instantiate an IniParser object
    IniParser parser;

    try {
        // Parse an existing INI file
        parser.parseFromFile("example.ini");

        // Access and modify data
        parser.setValue("Section1", "Key1", "NewValue");
        parser.addSection("NewSection");
        parser.setValue("NewSection", "NewKey", "Value");

        // Save modified data back to the INI file
        parser.saveToFile("example.ini");
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}

Handles Comments Gracefully

Example:

; This is a comment
# This is also a comment
[Section1]
Key1=Value1

API Reference

License

This project is licensed under the MIT License - see the LICENSE file for details.