Код: Выделить всё
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
int main() {
// Создание и заполнение unordered_map
std::unordered_map<std::string, std::vector<std::string>> myMap = {
{"key1", {"value1", "value2"}},
{"key2", {"value3", "value4"}},
{"key3", {"value5"}}
};
// Извлечение всех значений
for (const auto& pair : myMap) {
const std::string& key = pair.first; // ключ
const std::vector<std::string>& values = pair.second; // вектор значений
std::cout << "Ключ: " << key << "\nЗначения: ";
for (const auto& value : values) {
std::cout << value << " ";
}
std::cout << std::endl;
}
return 0;
}