MFC总结(7)--- 操作Ini文件 操作

本文介绍了如何在MFC中创建一个专门用于操作Ini文件的类,将读写Ini文件的方法封装起来,方便在项目中复用。详细讲述了类的定义和使用方法。
摘要由CSDN通过智能技术生成

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


MyIniClass.cpp文件

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值