超级简单,一看就会
//头文件config.h
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include <map>
class config
{
public:
config(char path[256]); //构造函数
~config(void);//析构函数
std::string option(char key[1024],char defaultvalue[1024]);
private:
//map的使用
std::map<std::string,std::string> maps;
char buf[1024];
};
#endif
//主文件config.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include "config.h"
using namespace std;
// 成员函数的实现
//去空格,作为函数出现,其他地方也可以用
string trim(string s)
{
s.erase(0,s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
return s;
}
//构造函数
config::config(char path[256]){
string buff;