vc读INI文件
/*test.ini
//
[index]
name=小朱
年龄=23
[index2]
sex=男
/
*/
#include "stdio.h"
#include "iostream.h"
#include "windows.h"
int main(int agrc,char *agrv[])
{
char buf[MAX_PATH];
DWORD size=MAX_PATH;
TCHAR tcPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,tcPath);
TCHAR *path=strcat(tcPath,"\\test.ini");
//获取字符串
GetPrivateProfileString("index","name","NULL",buf,size,path);
cout<<"获取字符串 "<<buf<<endl;
//获取整型值
int num=GetPrivateProfileInt("index","年龄",-1,path);
cout<<"获取整型值 "<<num<<endl;
//获取指定节下的信息
GetPrivateProfileSection("index",buf,size,path);
cout<<"获取指定节下的信息 "<<buf<<endl;
//获取所有节的名称
GetPrivateProfileSectionNames(buf,size,path);
cout<<"获取所有节的名称 "<<buf<<endl;
//获取指定建明的结构数据信息
GetPrivateProfileStruct("index","name",buf,size,path);
cout<<"获取指定建明的结构数据信息 "<<buf<<endl;
//写入指定节指定键名的字符串信息
WritePrivateProfileString("index","name","小朱",path);
GetPrivateProfileString("index","name","NULL",buf,size,path);
cout<<"获取更改后字符串 "<<buf<<endl;
// //写入指定节下的结构数据
// WritePrivateProfileSection("index2","kkk",path);
//
// //写入指定节指定键名下结构数据
// WritePrivateProfileStruct("index2","name","kkk",strlen("kkk"),path);
return 0;
}
文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。
原文链接:zzzili.blog.csdn.net/article/details/8265413
- 点赞
- 收藏
- 关注作者
评论(0)