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)
|
string loadFile2Str(const char * const filepath)
|
||||||
{
|
{
|
||||||
ifstream in(filepath, ios::in);
|
ifstream in(filepath);
|
||||||
istreambuf_iterator<char> beg(in), end;
|
istreambuf_iterator<char> beg(in), end;
|
||||||
string str(beg, end);
|
string str(beg, end);
|
||||||
in.close();
|
in.close();
|
||||||
|
@ -1,18 +1,41 @@
|
|||||||
/************************************
|
/************************************
|
||||||
* file enc : ascii
|
* file enc : ascii
|
||||||
* author : wuyanyi09@gmail.com
|
* author : wuyanyi09@gmail.com
|
||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef CPPCOMMON_MAP_FUNCTS_H
|
#ifndef CPPCOMMON_MAP_FUNCTS_H
|
||||||
#define CPPCOMMON_MAP_FUNCTS_H
|
#define CPPCOMMON_MAP_FUNCTS_H
|
||||||
|
|
||||||
#define PRINT_MAPSS(mpss) \
|
#include <map>
|
||||||
{\
|
#include <iostream>
|
||||||
for(map<string, string>::const_iterator it = mpss.begin(); it != mpss.end(); it++)\
|
|
||||||
{\
|
namespace CPPCOMMON
|
||||||
cout<<it->first<<' '<<it->second<<endl;\
|
{
|
||||||
}\
|
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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user