Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
2574 EC
//clang 3.8.0 #include <string> #include <iostream> #include <unordered_map> int main() { std::unordered_map<std::string, int> map;//Make an ordered map with the key being a string //Insert a number of items into the hashable map["first"] = 1; map["second"] = 2; map["third"] = 3; map["fourth"] = 4; //Retrieving an item that was inserted auto hashTablePointer = map.find("third"); if (hashTablePointer == map.end()) { std::cout << "I wasn't able to find \"third\" in the map" << std::endl; } else { std::cout << "I found \"third\" in the map, and it contains the value " << map["third"] << std::endl; } //Determining that item is not in hash table auto nextHashTablePointer = map.find("fifth"); if (nextHashTablePointer == map.end()) { std::cout << "As expected, I was not able to find an entry with the key \"fifth\" in the table" << std::endl; } //Print out all the items stored in the hash table std::cout << "The hash table contains the following items: " << std::endl; for (auto& item : map) { std::cout << item.second << std::endl; } }
run
|
edit
|
history
|
help
0
template specialization inheritance problem
Template Meta Programming
"nearest enclosing namespace"
11/29
Rounding float to nearest 1000
Mock Interview Question
C++17 function traits not works
overloadresolution
First
std::99 bottles of beer!