1、读写配置文件 ini首先介绍两个函数:读取 ini 文件:DWORD GetPrivateProfileString(LPCTSTR lpAppName, / points to section nameLPCTSTR lpKeyName, / points to key nameLPCTSTR lpDefault, / points to default stringLPTSTR lpReturnedString, / points to destination bufferDWORD nSize, / size of destination bufferLPCTSTR lpFileName
2、 / points to initialization filename);参数说明:lpAppName :ini 文件中的一个字段名lpKeyName :lpAppName 下的一个键名,也就是具体的变量名lpDefault :如果没有其前两个参数值,则将此值赋给变量lpReturnedString :接收 INI 文件中的值的 CString 对象,即目的缓存器nSize :目的缓存器的大小lpFileName :完整的 INI 文件路径名写入 ini 文件:BOOL WritePrivateProfileString(LPCTSTRlpAppName, / section nameLPC
3、TSTRlpKeyName, / key nameLPCTSTRlpString, / string to addLPCTSTRlpFileName / initialization file);参数说明:lpAppName :ini 文件中的一个字段名lpKeyName :lpAppName 下的一个键名,也就是具体的变量名lpString :是键值,也就是变量的值,必须为 LPCTSTR 或 CString 类型lpFileName :完整的 INI 文件路径名读取整型值:UINT GetPrivateProfileInt(LPCTSTRlpAppName, / section nameL
4、PCTSTRlpKeyName, / key nameINTnDefault, / return value if key name not foundLPCTSTRlpFileName / initialization file name);实例:写入:CString StrName,Strtemp;int nAge;char filename20 = “;StrName = “jacky“;nAge = 13;WritePrivateProfileString(“Student“,“Name“,StrName,“ressetting.ini“);读取:CString SName;GetPrivateProfileString(“Student“,“Name“,“DefaultName“,SName.GetBuffer(100),100,“ressetting.ini“);SName.ReleaseBuffer();MessageBox(SName);