转:c++builder读写INI文件

 
//包含文件

#include <inifiles.hpp>

//写文件

TIniFile *ini;
ini=new TIniFile(ChangeFileExt(ExtractFilePath(Application->ExeName),"config.cfg"));
ini->WriteInteger("Form","Top",Top);
ini->WriteInteger("Form","Left",Left);
ini->WriteString("Form","Caption",Caption);
ini->WriteBool("Form","InitMax",WindowState==wsMaximized);
delete ini;

//读文件

if(FileExists(ExtractFilePath(Application->ExeName)+"config.cfg"))//检测文件是否存在
{
TIniFile *ini;
ini=new TIniFile(ChangeFileExt(ExtractFilePath(Application->ExeName),"config.cfg"));

Top=ini->ReadInteger("Form","Top",100);
Left=ini->ReadInteger("Form","Left",100);
Caption =ini->ReadString("Form","Caption","Default Caption");
ini->ReadBool("Form","InitMax",false)?WindowState=wsMaximized:WindowState=wsNormal;
delete ini;
}
else
{
ShowMessage("文件不存在");
}

原文地址:https://www.cnblogs.com/dadamoney/p/1535683.html