脚本宝典收集整理的这篇文章主要介绍了[Modern C++]现代c++中的HashMap,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
背景
作为一门新时代的程序设计语言,c++11提供了默认的unordered_map类,拥有不错的效率。
使用方法(代码)
#include <iostream>
#include <functional>
#include <unordered_map>
int m = 1;
int main()
{
std::unordered_map<int,int> dict ({{1,2},{2,5}});
auto print = [](std::unordered_map<int,int> &dict)->void{
for (const auto& x: dict) std::cout << " " << x.first << ":" << x.second ;
std::cout << std::endl;
};
print(dict);
dict.insert({3,8});
print(dict);
dict.erase(1);
print(dict);
dict.erase(dict.end());
print(dict);
dict.clear();
print(dict);
return 0;
}
C:UsersliujXDocumentsworkspace>g++ -std=c++14 a.cc
C:UsersliujxDocumentsworkspace>a
2:5 1:2
3:8 2:5 1:2
3:8 2:5
以上是脚本宝典为你收集整理的[Modern C++]现代c++中的HashMap全部内容,希望文章能够帮你解决[Modern C++]现代c++中的HashMap所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。