1、建立一个操作Ini文件的类,将操作ini文件的相关方法都封装到该类中
MyIniClass.h文件
#pragma once
#include <vector>
using std::vector;
class CMyIniClass
{
public:
CMyIniClass();
virtual ~CMyIniClass();
// 设置ini文件路径
// 成功返回TRUE;否则返回FALSE
BOOL SetPath(CString strPath);
// 检查section是否存在
// 存在返回TRUE;否则返回FALSE
BOOL SectionExist(CString strSection);
// 从指定的Section和Key读取KeyValue
// 返回KeyValue
CString GetKeyValue(CString strSection,
CString strKey);
// 设置Section、Key以及KeyValue,若Section或者Key不存在则创建
void SetKeyValue(CString strSection,
CString strKey,
CString strKeyValue);
// 删除指定Section下的一个Key
void DeleteKey(CString strSection,
CString strKey);
// 删除指定的Section以及其下的所有Key
void DeleteSection(CString strSection);
// 获得所有的Section
// 返回Section数目
int GetAllSections(CStringArray& strArrSection);
// 根据指定Section得到其下的所有Key和KeyValue
// 返回Key的数目
int GetAllKeysAndValues(CString strSection,
CStringArray& strArrKey,
CStringArray& strArrKeyValue);
// 删除所有Section
void DeleteAllSections();
//初始化信息
void initIniFile(LPCTSTR path);
// 获取指定ini中节中所有的value
void getValue(CString strPath, CString strSections);
//返回vector
vector<CString> getValueVctr();
void getSysCurName(CString & strName);
private:
// ini文件路径
CString m_strPath;
vector<CString> m_valueVctr;
};
#include "stdafx.h"
#include "MyIniClass.h"
#define MAX_SECTION 260 //Section最大长度
#define MAX_KEY 260 //KeyValues最大长度
#define MAX_ALLSECTIONS 65535 //所有Section的最大长度
#define MAX_ALLKEYS 65535 //所有KeyValue的最大长度
CMyIniClass::CMyIniClass() : m_valueVctr(NULL)
{
}
CMyIniClass::~CMyIniClass()
{
}
//
// Pu