mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update cppcommon
This commit is contained in:
parent
05879ac6c3
commit
2c77ac8806
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user