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;	// ƒCƒeƒŒ[ƒ^

  mymap["–kŠC“Ή"] = "Hokkaido";
  mymap["ΒX"] = "Aomori";
  mymap["H“c"] = "Akita";
  mymap["ŠβŽθ"] = "Iwate";
  mymap["ŽRŒ`"] = "Yamagata";
  mymap["‹{ι"] = "Miyagi";
  mymap["•Ÿ“‡"] = "Fukushima";

  // ƒCƒeƒŒ[ƒ^‚πŽg‚Α‚Δ‘S—v‘f‚π—ρ‹“
  for (iter = mymap.begin (); iter != mymap.end (); iter++) {
    cout << (*iter).first << " is the japanese word for " << iter->
      second << endl;
  }

  // —v‘f‚π’Η‰Α
  mymap["“Œ‹ž"] = "Tokyo";

  // ƒCƒeƒŒ[ƒ^‚πŽg‚Α‚Δ‘S—v‘f‚π—ρ‹“
  printf ("\n");
  for (iter = mymap.begin (); iter != mymap.end (); iter++) {
    cout << (*iter).first << " is the japanese word for " << iter->
      second << endl;
  }

  // —v‘f‚ΙƒL[‚πŽg‚Α‚Δ’ΌΪƒAƒNƒZƒX‚·‚ι
  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
H“c is the japanese word for Akita
ΒX is the japanese word for Aomori
•Ÿ“‡ is the japanese word for Fukushima
–kŠC“Ή 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
H“c 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
–kŠC“Ή is the japanese word for Hokkaido

“Œ‹žTokyo

–ί‚ι

inserted by FC2 system