系统自带的头文件 #include <windows.h> 中,包含了ini的api,直接添加该头文件即可。
一、写入(整型 或 double/float)
::WritePrivateProfileString(节点, 键, 值, INI文件的路径);
LPTSTR lpPath = new char[MAX_PATH]; //MAX_PATH:是微软最大路径占的字节所设的宏
strcpy(lpPath, ".//A_zhongShi_holeAreaVal.ini");
值可以是整型也可以是double/float
::WritePrivateProfileString("hole", "area", "1", lpPath);
二、读取(整型 或 double/float)
读取 整型和 浮点型 的方法不同,实现方法如下所示:
1、读取整型
int areaValReal = GetPrivateProfileInt("hole", "area", 0, ".//A_zhongShi_holeAreaVal.ini");
2、读取 double/float
char areaVal[1024] = "";
GetPrivateProfileStringA("hole", "area", "", areaVal, sizeof(areaVal), ".//A_zhongShi_holeAreaVal.ini");
float areaValReal = atof(areaVal);