Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <unordered_map>
- int main() {
- std::unordered_map<std::string, int> m;
- m.insert({"Ivan", 5});
- m["Max"] = 5;
- m["Artyom"] = 55;
- std::cout << m["Ivan"] << std::endl;
- std::cout << m["Max"] << std::endl;
- std::cout << m["B"] << std::endl;
- std::cout << m.at("B") << std::endl;
- std::cout << m["A"] << std::endl;
- // auto it = m.find("Stepa");
- // if (it != m.end()) {
- // it->second = 3;
- // }
- std::cout << m["Stepa"] << std::endl;
- std::map<std::string, int> mm;
- mm.insert({"Ivan", 5});
- mm["Max"] = 5;
- mm["Artyom"] = 55;
- std::cout << mm["Ivan"] << std::endl;
- std::cout << mm["Max"] << std::endl;
- std::cout << mm["B"] << std::endl;
- std::cout << mm["A"] << std::endl;
- // auto it = m.find("Stepa");
- // if (it != m.end()) {
- // it->second = 3;
- // }
- std::cout << mm["Stepa"] << std::endl << std::endl;
- std::cout << "Unordered map:" << std::endl;
- for (auto& [key, value] : m) {
- std::cout << key << " " << value << std::endl;
- }
- std::cout << "Map:" << std::endl;
- for (auto& [key, value] : mm) {
- std::cout << key << " " << value << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement