simpleini项目地址:
https://github.com/brofield/simpleini
下载,新建项目,并将SimpleIni.h文件通过包含目录的方式加载进来。
创建test.ini文件,内容如下:
[server]
root = 10.1.1.1
gc = 10.1.1.2
game = 10.1.1.3
写码:
#include "pch.h"
#include <iostream>
#include <SimpleIni.h>
using namespace std;
int main()
{
CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile("test.ini");
const char * pVal = ini.GetValue("server", "game", "default");
ini.SetValue("server", "game", "10.1.1.5");
const char * xVal = ini.GetValue("server", "game", "default");
cout << pVal << endl;
cout << xVal << endl;
// save the data back to the file
int rc = ini.SaveFile("test.ini");
if (rc < 0) return false;
}
打开test.ini文件会发现game一行内容改变。
/**
*
* __ (__`\
* (__`\ \\`\
* `\\`\ \\ \
* `\\`\ \\ \
* `\\`\#\\ \#
* \_ ##\_ |##
* (___)(___)##
* (0) (0)`\##
* |~ ~ , \##
* | | \##
* | /\ \## __..---'''''-.._.._
* | | \ `\## _.--' _ `.
* Y | \ `##' \`\ \
* / | \ | `\ \
* /_...___| \ | `\\
* / `. | / ##
* | | | / ####
* | | | / ####
* | () () | \ | | _.-' ##
* `. .' `._. |______..| |-'|
* `------' | | | | | || |
* | | | | | || |
* | | | | | || |
* | | | | | || |
* _____ | | | |____| || |
* / `` |-`/ ` |` |
* \________\__\_______\__\
* """"""""" """""""'"""
* Don't be a fucking stupid donkey! No, this is a fucking mule!
*/