/*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; }