请问如何获取ini文件中的内容?分不够我另开帖子在加。急。。。随时恭候解答。谢谢了。

ilovc 2001-12-01 11:19:28
比如说在ini文件中有3行
a=1
b=2
c=try
创建一个基于对话框程序,添加2个Edit box,一个static text,和一个button
当click button时
把ini文件中的a和b的值分别读入到Edit box中
把c读入到static text;
谢谢了
...全文
173 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
joke100 2001-12-03
  • 打赏
  • 举报
回复

我想是不是检查一下你的ini文件呀,比如路径文件名,特别是文件里的section一定要用方括号括起来,象上面提到的
[MyData]
a=1
b=2
c=try
第一行就是section
ilovc 2001-12-01
  • 打赏
  • 举报
回复
照各位的方法一试,编译无误,但是得不到值啊。为什么呀?
是不是因为GetPrivateProfileInt(),是基于16位的?
32位该如何处理啊?
ilovc 2001-12-01
  • 打赏
  • 举报
回复
谢谢各位,我先试试。
MHB 2001-12-01
  • 打赏
  • 举报
回复
//your.ini文件结构
[YourApp]
a=1
b=2
c=try
//------------------------------
char buff[10];
//取a内容
memset(buff,0,sizeof(buff));
GetPrivateProfileString("YourApp","a","",buff,sizeof(buff),"Your.ini");
EditBox1变量=buff; //<--------------注意
//取b内容
memset(buff,0,sizeof(buff));
GetPrivateProfileString("YourApp","b","",buff,sizeof(buff),"Your.ini");
EditBox2变量=buff; //<--------------注意
//取c内容
memset(buff,0,sizeof(buff));
GetPrivateProfileString("YourApp","c","",buff,sizeof(buff),"Your.ini");
StaticText1变量=buff; //<--------------注意

LXJ2001 2001-12-01
  • 打赏
  • 举报
回复
看MSDN关于:
CWinApp::m_pszProfileName
CWinApp::GetProfileString
CWinApp::SetRegistryKey
joke100 2001-12-01
  • 打赏
  • 举报
回复
使用API
UINT GetPrivateProfileInt(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
INT nDefault, // return value if key name not found
LPCTSTR lpFileName // initialization file name
);取整型变量值
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpDefault, // default string
LPTSTR lpReturnedString, // destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // initialization file name
);取字符串型值

如果
你的ini文件如下形式,文件名为c:\mydata.ini.
[MyData]
a=1
b=2
c=try

那么如下调用:
int naValue = ::GetPrivateProfileInt ("MyData", "a", 0, "c:\\mydata.ini");取a值
int nbValue = ::GetPrivateProfileInt ("MyData", "b", 0, "c:\\mydata.ini");取b值
调用
char cValue[100];
::GetPrivateProfileString("MyData", "c", NULL, cValue, 100, "c:\\mydata.ini");取c值,c字符串放在cValue中,100是为字符串预分配的内存空间。


c7654321 2001-12-01
  • 打赏
  • 举报
回复
同意楼上
chanhao 2001-12-01
  • 打赏
  • 举报
回复
看MSDN
getprivateprofilestring
getprivateprofilesection
等,你将会得到答案
ilovc 2001-12-01
  • 打赏
  • 举报
回复
u p

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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