windows中ini配置文件的读取

GetPrivateProfileInt

Config.ini

[Student]
nAge=12

int Result = GetPrivateProfileInt("Student", "nAge", 0, "Config.ini");

为什么下面的语句读取不出来,每次都是Result = 0.也就是默认值?因为"Config.ini"是错误的路径,应该写成"./Config.ini"

int Result = GetPrivateProfileInt("Student", "nAge", 0, "./Config.ini");

GetPrivateProfileString

Config.ini

[Student]
nAge=12

[stringtest]
nnn = adf

int Result = GetPrivateProfileInt("Student", "nAge", 0, "./Config.ini");
	char aaa[4];
	GetPrivateProfileString("stringtest", "nnn", "-", aaa, sizeof(aaa) + 1, "./Config.ini");
	printf("%s\n", aaa);

读入字符串,区别仅仅是读取的时候认为读取的这个值是字符串,经过测试发现:当用string读取的时候,等号右边的值,两头可以加上单引号或者双引号,实际读取的时候自动忽略掉了,而字符串中间的单引号或者双引号都会认为是字符的一部分保留下来。
比如:

nnn = "adf.co"m"

输出:
在这里插入图片描述

参考来源链接

windows ini文件读取注意事项

Guess you like

Origin blog.csdn.net/u011913417/article/details/119419328