今天想测试一下ini配置文件的信息,写了一个Windows控制台项目,调用了GetPrivateProfileString函数。
发现每次读取的信息都有误,只读取到字符串的第一个字符,查看以前自己写的代码,对比发现没有一丝不同。
烦恼了一个多小时,突然想起可能是编码问题,于是将项目属性-》字符集"使用unicode字符集“改成“使用多字节字符集”。
运行成功,读取的信息如自己所愿。
CFileFind finder;
BOOL bIsFind = finder.FindFile(_T(".\\test.ini"));
char str[100];
if(bIsFind)
{
bIsFind = finder.FindNextFile();
CString szFilePath = finder.GetFilePath();
GetPrivateProfileString(_T("Setting"), _T("String"), NULL, str , 100, szFilePath);
}
test.ini :
[Setting]
String = test
对了,补充一下,ini配置文件是ASCII编码。