linux中使用hashmap
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
#include "apue.h"
#include <iostream>
#include <string>
#include <list>
#include <cstddef>
#include "Sales_item.h"
#include <vector>
#include <map>
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
using namespace std;
namespace std
{
using namespace __gnu_cxx;
}
int main(void){
hash_map<int,int> hm;
hm.insert(pair<int,int>(1,2));
hm.insert(pair<int,int>(2,3));
hash_map<int,int>::iterator it=hm.begin();
for(;it!=hm.end();it++)
cout<<it->first<<"\t"<<it->second<<endl;
return 0;
}
在处理string作为key时需要下面处理方式
#include "apue.h"
#include <iostream>
#include <string>
#include <list>
#include <cstddef>
#include "Sales_item.h"
#include <vector>
#include <map>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
namespace __gnu_cxx {
template<> struct hash<std::string> {
size_t operator()(const std::string& x) const {
return hash<const char*>()(x.c_str());
}
};
}
int main() {
hash_map<string, int> str_hash;
str_hash["text"] = 2;
str_hash.insert(pair<string,int>("3223",22));
cout << str_hash["text"] <<endl;
return 0;
}
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献1条内容
所有评论(0)