#include <iostream>
#include <map>
int main() {
std::map<int, float> num_map;
// calls a_map.begin() and a_map.end()
for (auto it = num_map.begin(); it != num_map.end(); ++it) {
std::cout << it->first << ", " << it->second << '
';
}
}
// C++17 and above
for (auto const& [key, value] : map)
{
// do something
}
// C++11 and onwards
for (auto const& keyValue : map)
{
keyValue.first; // Key
keyValue.second; // Value
}
for (auto i : m)
cout << i.first << " " << i.second
<< endl;
// Single line to get the pair:
std::pair<key_t, value_t> pair = *std::next(map.begin(), at);
// To get the iterator:
auto itr = std::next(map.begin(), at);