zettelkasten
Maps
Last updated: 1/9/2025
Maps are a way of storing data with a key-value pair.
C++: Use the map.at() function so that you don't accidentally create new key-value pairs in the map. The preferred way to populate a map with a key-value pair is to use the built-in std::pair class:
c++
std::map<std::string, int> frequency;frequency.insert(std::pair<std::string, int>("Howdy",1));// ORfrequency.insert({"Howdy", 1});This is how you iterate through a map:
c++
for (auto const& [key, value] : your_map) { std::cout << key << ':' << value << std::endl;}Use std::map.contains(key); to see if a map contains a given key
See Also
- [[computer-science]]
- [[Compound Data]]