skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-map
This page is read only. You can view the source, but not change it.
# <map> **[<map>](https://en.cppreference.com/w/cpp/header/map)** is an ordered associative container: a sorted tree of key-value pairs with O(log n) insertion, deletion, and lookup. It maintains keys in sorted order and allows iteration from min to max. Use `std::unordered_map` if you don't need order; use `std::map` if you do or if you need to iterate a range of keys. This example builds a map of names to ages, iterates through in sorted order, and looks up a specific key. ```cpp // compile: g++ -std=c++11 -o mapexample mapexample.cpp // run: ./mapexample // description: map insertion and lookup #include <map> #include <iostream> #include <string> int main() { std::map<std::string, int> age; age["alice"] = 30; age["bob"] = 25; age["charlie"] = 35; for (const auto& [name, years] : age) { std::cout << name << ": " << years << "\n"; } std::cout << "alice is " << age["alice"] << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top