std::map
map stores sorted key value pairs. Use [], at, find, count and erase.
Example
#include <iostream>
#include <map>
#include <string>
int main() {
std::map<std::string, int> m;
m["b"] = 2; m["a"] = 1;
for (auto &[k, v] : m) std::cout << k << "=" << v << " ";
std::cout << m.count("a") << " " << (m.find("z") == m.end()) << "\n";
return 0;
}Result
a=1 b=2 1 1
Exercise
Sorted pairs.
std::<std::string, int>
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.