diff --git a/src/cppcommon/io_functs.cpp b/src/cppcommon/io_functs.cpp index f04a3bb..e966bb7 100644 --- a/src/cppcommon/io_functs.cpp +++ b/src/cppcommon/io_functs.cpp @@ -8,7 +8,7 @@ namespace CPPCOMMON { string loadFile2Str(const char * const filepath) { - ifstream in(filepath, ios::in); + ifstream in(filepath); istreambuf_iterator beg(in), end; string str(beg, end); in.close(); diff --git a/src/cppcommon/map_functs.h b/src/cppcommon/map_functs.h index 833da38..6c8a411 100644 --- a/src/cppcommon/map_functs.h +++ b/src/cppcommon/map_functs.h @@ -1,18 +1,41 @@ /************************************ * file enc : ascii * author : wuyanyi09@gmail.com -************************************/ + ************************************/ #ifndef CPPCOMMON_MAP_FUNCTS_H #define CPPCOMMON_MAP_FUNCTS_H -#define PRINT_MAPSS(mpss) \ -{\ - for(map::const_iterator it = mpss.begin(); it != mpss.end(); it++)\ - {\ - cout<first<<' '<second< +#include + +namespace CPPCOMMON +{ + using namespace std; + + + template + void printMap(const map& mp) + { + for(typename map::const_iterator it = mp.begin(); it != mp.end(); it++) + { + cout<first<<' '<second< + vT getMap(const map& mp, const kT & key, const vT & defaultVal) + { + typename map::const_iterator it; + it = mp.find(key); + if(mp.end() == it) + { + return defaultVal; + } + return it->second; + } + } #endif