#include <iostream>
#include <map>
#include <string>
int main() {
std::map<std::string, int> ages;
// Inserting elements
ages["Alice"] = 30;
ages.insert({"Bob", 25});
ages.insert(std::make_pair("Charlie", 35));
// Accessing elements
std::cout << "Alice's age: " << ages["Alice"] << std::endl;
// Checking if a key exists
if (ages.find("David") == ages.end()) {
std::cout << "David is not in the map" << std::endl;
}
// Iterating through the map
for (const auto& pair : ages) {
std::cout << pair.first << " is " << pair.second << " years old" << std::endl;
}
// Size of the map
std::cout << "Number of entries: " << ages.size() << std::endl;
// Removing an element
ages.erase("Bob");
return 0;
}