| Perl, PHP | Associated Array |
| Python | dictionary |
| Java | ~cpp HashMap, Hashtable |
| STL(C++) | map |
~cpp #include <map>
~cpp // map<key_type, value_type> map<string, long> m;
~cpp m["홍길동"] = 20;
~cpp
// for 에서 반복자 이용 순회
for(map<int, int>::iterator i; i = m.begin() ; i != m.end() ; ++i) {
cout << "key: " << (*i).first
<< "value: " << (*i).second << endl;
}
~cpp
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, long> directory;
directory["홍길동"] = 1234567l;
directory["김철수"] = 9876543l;
directory["김봉남"] = 3459876l;
cout << "전화 번호부의 내용은 " <<endl;
map<string, long>::iterator i;
i = directory.begin();
for ( ; i != directory.end();i++)
cout << "이름:" << (*i).first
<< " 전화번호: " << (*i).second << endl;
cout << "입니다. "<<endl;
string name;
while( cin >> name ){
if ( name.compare("exit") ==0)break;
cout << "이름을 입력해 주세요.(종료:exit):";
if (directory.find(name) != directory.end())
cout << name << "의 전화번호는"
<< directory[name] << "입니다.n";
else
cout << "죄송합니다. 그 이름이 전화 번호부에 없습니다." << name << "n";
}
return 0;
}