阅读背景:

cocos2d-x 读取CSV文件,读取本地Excel配置表的方法

来源:互联网 

//CSVReader.h


#define MAP_LINE std::map<std::string, std::string>			//key为首行字符串, value为此列字符串
#define MAP_CONTENT std::map<int, MAP_LINE>				//key为code, value为一行map
#define VEC_MAP  std::vector<std::pair<std::string, int>>

//csv文件读取器
class CSVReader
{
public:
	CSVReader();
	static CSVReader *getInst();	//获取实例

	//解析csv. fileName:csv文件名,
	void parse(const char *fileName);

	//获取内容map. filename:文件名
	const MAP_CONTENT &getContentMap(std::string filename);
	//获取一行map.filename:文件名, code一行code
	const MAP_LINE &getLineMap(std::string filename, int code);
	//获取某行某列的值
	const std::string  &getByCode(std::string filename, int code, const std::string &key);
private:
	//读取csv的一行.line:一行的内容
	void readCSVLine(const char *line, int index);

	 VEC_MAP m_firstVector;											//第一行的vector
	 MAP_CONTENT m_contentMap;									//内容map
	 std::map<std::string, MAP_CONTENT> m_fileMap;		//文件map

	 static CSVReader *m_inst;		//实例
};#define MAP_LINE std::map



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: