您的位置:首页 > 其它

读写ini配置文件时的相对路径问题

2014-07-03 19:06 393 查看
在使用GetPrivateProfileString时需要注意一点,

DWORD WINAPI GetPrivateProfileString(
  _In_   LPCTSTR lpAppName,
  _In_   LPCTSTR lpKeyName,
  _In_   LPCTSTR lpDefault,
  _Out_  LPTSTR lpReturnedString,
  _In_   DWORD nSize,
  _In_   LPCTSTR lpFileName
);


其参数中

lpFileName [in]
The name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.

当参数不包含文件全路径时,系统会在Windows中寻找该文件,而并不是我们习惯性认为的在当前工作目录下寻找。

当我们以"./test.ini"作为参数传入时,系统会在当前工作目录下读写test.ini文件,但是我们仅为"test.ini"文件作为参数传入时,系统仅会在X:/Windows目录下查找“test.ini”文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: