Giter Club home page Giter Club logo

readini's Introduction

readini

*.ini文件解析工具

运行测试

mkdir build && cd build
cmake .. && make
./readini filepath

使用方法

test.ini内容

; MySQL配置
[MySQL]
host=127.0.0.1
port=3306
user=root
password=123456

在你的项目中引入iniconfig.h头文件

#include <iostream>
#include <fstream>
#include "iniconfig.h"

using namespace std;

int main() {
    string file("file.ini");
    fstream input(file, ios::in);
    
    ini::IniConfig iniConfig;
    
    try {
        //解析
        iniConfig.parse(input);
        
        //取值
        ini::Parameters mysql = iniConfig["MySQL"];
        string host = mysql["host"].asString();
        int port = mysql["port"].asInt();
        string user = mysql["user"].asString();
        string pwd = mysql["password"].asString();
        
        cout << "主机: " << host << endl;
        cout << "端口: " << port << endl;
        cout << "用户名: " << user << endl;
        cout << "密码: " << pwd << endl;
        
    } catch (const ios_base::failure& e1) {
        cerr << e1.what() << endl;
    } catch (const Ini::ErrorLog& e2) {
        cerr << e2.what() << endl;
    }
    return 0;
}

输出

主机: 127.0.0.1
端口: 3306
用户名: root
密码: 123456

readini's People

Contributors

lee-land avatar

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.