天天看点

Windows10 VS2017 C++ ini解析(使用simpleini头文件)

版权声明:本文可能为博主原创文章,若标明出处可随便转载。 https://blog.csdn.net/Jailman/article/details/85266402

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一行内容改变。