Skip to content

Instantly share code, notes, and snippets.

@chmnoh
Created February 11, 2017 12:51
Show Gist options
  • Save chmnoh/d2bf650d9af9630a08d2baec34b94d25 to your computer and use it in GitHub Desktop.
Save chmnoh/d2bf650d9af9630a08d2baec34b94d25 to your computer and use it in GitHub Desktop.
unordered_map test
#include <iostream>
#include <string>
#include <unordered_map>
int main()
{
std::string name;
std::unordered_map<int,int> mymap;
mymap.insert(std::make_pair<int,int>(1229,1));
mymap.insert(std::make_pair<int,int>(8,0));
mymap.insert(std::make_pair<int,int>(17,1));
for (auto& x: mymap) {
std::cout << x.first << ":" << x.second << std::endl;
}
std::unordered_map<int,int>::const_iterator item = mymap.find(17);
if (item==mymap.end()) {
std::cout << "not found" << std::endl;
} else {
std::cout << "found for " << item->first << ":" << item->second << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment