c++ unordered_map 사용 예시


#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
 
void insertItem(unordered_map<int, string>& items, const int& key, const string& value) {
    items.insert(unordered_map<int, string>::value_type(key, value));
}
 
string getItem(unordered_map<int, string>& items, const int& key) {
    return items[key];
}
 
void main() {
    unordered_map<int, string> items;
 
    insertItem(items, 0, "Park");
    insertItem(items, 1, "Kim");
    insertItem(items, 2, "Hong");
    insertItem(items, 3, "Choi");
    
    for (int i = 0; i < 4; i++) {
        printf("%d - %s\n", i, getItem(items, i).c_str());
    }
}