map and unordered_map
Key–value containers: map keeps keys sorted (tree), unordered_map uses hashing for faster lookups.
Intermediate
std::unordered_map<std::string, int> pins = {{"LED", 13}, {"BUZZER", 8}};
pins["SERVO"] = 9;
if (auto it = pins.find("LED"); it != pins.end())
std::cout << it->second; // 13
map | unordered_map | |
|---|---|---|
| Order | sorted by key | none |
| Lookup | average |
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.