GetPrivateProfileInt 简单的很的函数 在线等 马上给分

zyb_debug 2008-08-01 09:42:34
无语
int main()
{
int m = GetPrivateProfileInt("test","mm",-1,"a.ini");
cout << m ;
return 0;
}
这个我的main函数

这个是ini文件 但是输出老是-1;
why 在线等
...全文
367 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
可微函树 2008-08-01
  • 打赏
  • 举报
回复
GetPrivateProfileInt()返回的是五符号整型 你为什么用int存储返回值?
hai040 2008-08-01
  • 打赏
  • 举报
回复
可能不能有空格
zyb_debug 2008-08-01
  • 打赏
  • 举报
回复
果然如此 6楼 .\\是什么意思
jay的Fans 2008-08-01
  • 打赏
  • 举报
回复
那应该是LZ的那个文件的路径错误了。
xkyx_cn 2008-08-01
  • 打赏
  • 举报
回复
把a.ini放在工程的目录下,不要放在debug、release等目录下
wangdeqie 2008-08-01
  • 打赏
  • 举报
回复

//也可以这么写
---a.ini---
//a.ini里的内容:
[test]
mm=4000
//---main.cpp---
#include <iostream.h>
#include <windows.h>
int main()
{
int m = GetPrivateProfileInt("test","mm",-1, ".\\a.ini");
cout << m ;
return 0;
}


太乙 2008-08-01
  • 打赏
  • 举报
回复
key前面不能有空格哦~
wuyu637 2008-08-01
  • 打赏
  • 举报
回复
arameters
lpAppName
[in] Pointer to a null-terminated string specifying the name of the section in the initialization file.
lpKeyName
[in] Pointer to the null-terminated string specifying the name of the key whose value is to be retrieved. This value is in the form of a string; the GetPrivateProfileInt function converts the string into an integer and returns the integer.
nDefault
[in] Default value to return if the key name cannot be found in the initialization file.
lpFileName
[in] Pointer to a null-terminated string that specifies 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.


=======================

int m = GetPrivateProfileInt("test","mm",-1,"a.ini");

第三个参数是你设定的如果在配置文件中找不到所要找的key的时候的返回值。。

你的文件中应该是找不到把,所以返回-1.。
太乙 2008-08-01
  • 打赏
  • 举报
回复
看来应该是没找到文件吧~~lz确定文件的命名以及路径正确?
wangdeqie 2008-08-01
  • 打赏
  • 举报
回复

---a.ini---
[test]
mm=4000

//这么写
#include <iostream.h>
#include <windows.h>
int main()
{
int m = GetPrivateProfileInt("test","mm",4069, ".\\a.ini");
cout << m ;
return 0;
}
zyb_debug 2008-08-01
  • 打赏
  • 举报
回复
为什么我的老是返回-1哦
太乙 2008-08-01
  • 打赏
  • 举报
回复
[section]
key=value
.
.
.
太乙 2008-08-01
  • 打赏
  • 举报
回复
UINT WINAPI GetPrivateProfileInt(
__in LPCTSTR lpAppName,
__in LPCTSTR lpKeyName,
__in INT nDefault,
__in LPCTSTR lpFileName
);
Parameters
lpAppName [in]
The name of the section in the initialization file.

lpKeyName [in]
The name of the key whose value is to be retrieved. This value is in the form of a string; the GetPrivateProfileInt function converts the string into an integer and returns the integer.

nDefault [in]
The default value to return if the key name cannot be found in the initialization file.

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.

Return Value
The return value is the integer equivalent of the string following the specified key name in the specified initialization file. If the key is not found, the return value is the specified default value.

jay的Fans 2008-08-01
  • 打赏
  • 举报
回复
[test]
mm = 10

代码正常。
这是a.ini文件中数值。
zyb_debug 2008-08-01
  • 打赏
  • 举报
回复
这个是ini文件里面的 我用txt写好后后缀名转换为ini
[test]
mm = 100

64,653

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧