Code Monkey home page Code Monkey logo

iniparser's Introduction

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

  • Parse INI files and access their contents.
  • Add, modify, or remove sections, keys, and values.
  • Save modified data back to the INI file.

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

  • parseFromFile(const std::string& filename): Parse an INI file specified by the filename.
  • getValue(const std::string& section, const std::string& key): Get the value associated with a key in a specific section.
  • setValue(const std::string& section, const std::string& key, const std::string& value): Set the value of a key in a specific section.
  • addSection(const std::string& section): Add a new section to the INI file.
  • removeSection(const std::string& section): Remove a section and all its contents from the INI file.
  • removeKey(const std::string& section, const std::string& key): Remove a key from a specific section.
  • saveToFile(const std::string& filename): Save the current state of the INI file to a new file.

License

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

iniparser's People

Contributors

90th avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lnodesl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.