Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14497321
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 20:53:51

下载本文示例代码
  在我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下:  一.将信息写入.INI文件中.  1.所用的WINAPI函数原型为: BOOL WritePrivateProfileString(LPCTSTR lpAppName,LPCTSTR lpKeyName,LPCTSTR lpString,LPCTSTR lpFileName);  其中各参数的意义:   LPCTSTR lpAppName 是INI文件中的一个字段名.   LPCTSTR lpKeyName 是lpAppName下的一个键名,通俗讲就是变量名.   LPCTSTR lpString 是键值,也就是变量的值,不过必须为LPCTSTR型或CString型的.   LPCTSTR lpFileName 是完整的INI文件名.  2.具体使用方法:设现有一名学生,需把他的姓名和年龄写入 c:\stud\student.ini 文件中. CString strName,strTemp;int nAge;strName="张三";nAge=12;::WritePrivateProfileString("StudentInfo","Name",strName,"c:\\stud\\student.ini");  此时c:\stud\student.ini文件中的内容如下:   [StudentInfo]   Name=张三  3.要将学生的年龄保存下来,只需将整型的值变为字符型即可: strTemp.Format("%d",nAge);::WritePrivateProfileString("StudentInfo","Age",strTemp,"c:\\stud\\student.ini");共3页。 1 2 3 :   在我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下:  一.将信息写入.INI文件中.  1.所用的WINAPI函数原型为: BOOL WritePrivateProfileString(LPCTSTR lpAppName,LPCTSTR lpKeyName,LPCTSTR lpString,LPCTSTR lpFileName);  其中各参数的意义:   LPCTSTR lpAppName 是INI文件中的一个字段名.   LPCTSTR lpKeyName 是lpAppName下的一个键名,通俗讲就是变量名.   LPCTSTR lpString 是键值,也就是变量的值,不过必须为LPCTSTR型或CString型的.   LPCTSTR lpFileName 是完整的INI文件名.  2.具体使用方法:设现有一名学生,需把他的姓名和年龄写入 c:\stud\student.ini 文件中. CString strName,strTemp;int nAge;strName="张三";nAge=12;::WritePrivateProfileString("StudentInfo","Name",strName,"c:\\stud\\student.ini");  此时c:\stud\student.ini文件中的内容如下:   [StudentInfo]   Name=张三  3.要将学生的年龄保存下来,只需将整型的值变为字符型即可: strTemp.Format("%d",nAge);::WritePrivateProfileString("StudentInfo","Age",strTemp,"c:\\stud\\student.ini");共3页。 1 2 3 : 下载本文示例代码


用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件用Visual C 操作INI文件
阅读(101) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~