Created
February 11, 2017 12:51
-
-
Save chmnoh/d2bf650d9af9630a08d2baec34b94d25 to your computer and use it in GitHub Desktop.
unordered_map test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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