参考来源:https://blog.csdn.net/m_buddy/article/details/54097131
目录
Ini文件格式
源码
//IniFile.h
#ifndef INIFILE_H_
#define INIFILE_H_
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
using std::string;
using std::vector;
using std::map;
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cout;
using std::stringstream;
//ini节点
class CSection
{
public:
CSection(const string& section, const string& key, const string& value);
string m_section;
string m_key;
string m_value;
};
//ini 键 值 对
class CKeyValue
{
public:
void AddKeyValue(const string& key, const string& value);
map<string, string> m_keyValue;
};
class CIniFile
{
public:
CIniFile();
~CIniFile();
bool LoadFromIni(const string& filename);
vector<CSection>::size_type SetValue(const string& section, const string& key, const string& value);
map<string, CKeyValue>::size_type GetSize();
bool SaveToIni(const string& path);
string GetValue(const string& section, const string& key);
void StrToInt(const string& str, int& num);
void StrToDouble(const string& str, double& num);
void strToChar(const string& str, char& num);
string FolderPath();
//返回一个不含strOld
string strReplaceAll(const string& strResource, const string& strOld, const string& strNew);
//去首尾空格
string& Trim(string& str);
private:
map<string, CKeyValue> m_secKeyValue;
};
#endif
//IniFile.cpp
#include "stdafx.h"
#include <windows.h>
#include "IniFile.h"
CSection::CSection(const stri