资源描述:
《C++中ini文件读取类.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Ini文件读取类在.h文件中的定义以及相应函数声明。classCIniFile:publicCObject{private:CStringm_AppPath;//ThePathofCurrentApplicationCStringArraym_SectionList;//TheListofSectionaboutINIFileintm_iSectionLen;public:#defineMAX_ALLSECTION_LEN4096#defineMAX_FNAME_LEN260#defineBufSize16384CStringm_iniFileName;//
2、TheNameofFileabout.INICIniFile(CStringFileName);virtual~CIniFile();voidsetFileName(CStringFileName);booleanSectionExists(constCString&Section);//booleanValueExists(constCString&Section,constCStringIdent);//READvoidReadSections();voidReadSection(constCString&Section,CStringArray&Str
3、ings);voidReadSectionValues(constCString&Section,CStringArray&Strings);CStringReadString(constCString&Section,constCString&Ident,constCString&Default);//CStringReadString(constCStringSection,constCStringIdent,constCStringDefault);intReadInteger(constCString&Section,constCString&Ide
4、nt,constint&Default);booleanReadBool(constCString&Section,constCString&Ident,constboolean&Default);//WRITEvoidWriteString(constCString&Section,constCString&Ident,constCString&Value);voidWriteInteger(constCString&Section,constCString&Ident,constint&Value);voidWriteBool(constCString&
5、Section,constCString&Ident,constboolean&Value);voidEraseSection(CStringSection);voidDeleteKey(constCString&Section,constCString&Ident);voidUpdateFile();CStringGetMaxAllSectionLen();booleanFileExists();intFileAge(CString&FileName);};下面是cpp文件中的函数定义#include"stdafx.h"#include"IniFile.h
6、"#ifdef_DEBUG#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#definenewDEBUG_NEW#endif////////////////////////////////////////////////////////////////////////Construction/Destruction///////////////////////////////////////////////////////////////////////*****************************Ex
7、ample*****************************FileName="\Data\HGG.ini";*/CIniFile::CIniFile(CStringFileName){ASSERT(FileName);m_iniFileName=FileName;ReadSections();}CIniFile::~CIniFile(){UpdateFile();}booleanCIniFile::SectionExists(constCString&Section){ASSERT(m_SectionList.GetSize()>0);//if
8、(m_SectionList.GetSize()<=