g++Εhash mapπg€
ίι
#include <iostream>
#include <string>
#include <map>
/**
* $Id: hashmap-by-using-STL.html,v 1.1 2009/06/22 16:12:12 kishi Exp kishi $
*/
using namespace std;
int
main (int argc, char *argv[])
{
map < string, string > mymap;
map < string, string >::iterator iter; // Ce[^
mymap["kCΉ"] = "Hokkaido";
mymap["ΒX"] = "Aomori";
mymap["Hc"] = "Akita";
mymap["βθ"] = "Iwate";
mymap["R`"] = "Yamagata";
mymap["{ι"] = "Miyagi";
mymap[""] = "Fukushima";
// Ce[^πgΑΔSvfπρ
for (iter = mymap.begin (); iter != mymap.end (); iter++) {
cout << (*iter).first << " is the japanese word for " << iter->
second << endl;
}
// vfπΗΑ
mymap[""] = "Tokyo";
// Ce[^πgΑΔSvfπρ
printf ("\n");
for (iter = mymap.begin (); iter != mymap.end (); iter++) {
cout << (*iter).first << " is the japanese word for " << iter->
second << endl;
}
// vfΙL[πgΑΔΌΪANZX·ι
printf ("\n");
cout << "" << mymap[""] << endl;
return 0;
}
‘ΐsΚ
$ !make && ./my-hash-test.exe
make my-hash-test && ./my-hash-test.exe
g++ my-hash-test.cpp -o my-hash-test
βθ is the japanese word for Iwate
{ι is the japanese word for Miyagi
R` is the japanese word for Yamagata
Hc is the japanese word for Akita
ΒX is the japanese word for Aomori
is the japanese word for Fukushima
kCΉ is the japanese word for Hokkaido
βθ is the japanese word for Iwate
{ι is the japanese word for Miyagi
R` is the japanese word for Yamagata
Hc is the japanese word for Akita
ΒX is the japanese word for Aomori
is the japanese word for Tokyo
is the japanese word for Fukushima
kCΉ is the japanese word for Hokkaido
Tokyo
ίι