update cppcommon

This commit is contained in:
gwdwyy 2013-08-14 17:32:11 +08:00
parent 05879ac6c3
commit 2c77ac8806
2 changed files with 31 additions and 8 deletions

View File

@ -8,7 +8,7 @@ namespace CPPCOMMON
{
string loadFile2Str(const char * const filepath)
{
ifstream in(filepath, ios::in);
ifstream in(filepath);
istreambuf_iterator<char> beg(in), end;
string str(beg, end);
in.close();

View File

@ -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<string, string>::const_iterator it = mpss.begin(); it != mpss.end(); it++)\
{\
cout<<it->first<<' '<<it->second<<endl;\
}\
#include <map>
#include <iostream>
namespace CPPCOMMON
{
using namespace std;
template<class kT, class vT>
void printMap(const map<kT, vT>& mp)
{
for(typename map<kT, vT>::const_iterator it = mp.begin(); it != mp.end(); it++)
{
cout<<it->first<<' '<<it->second<<endl;
}
}
template<class kT, class vT>
vT getMap(const map<kT, vT>& mp, const kT & key, const vT & defaultVal)
{
typename map<kT, vT>::const_iterator it;
it = mp.find(key);
if(mp.end() == it)
{
return defaultVal;
}
return it->second;
}
}
#endif