본문 바로가기

카테고리 없음

mfc map class 맵 클래스

// Map은 Array와는 다르게 크기를 별도로 지정하지 않고 생성하는 즉시 바로 넣음

  CMapStringToString map;
  map["사과"] = "Apple"; // map[key_value] = "value"
  map["딸기"] = "Strawberry";
  map["포도"] = "Grape";
  map["우유"] = "Milk";

 

  // map내의 원하는 값을 찾아서 출력
  CString str;
  if(map.Lookup("딸기", str)) // 딸기라는 key값을 갖는 것을 찾아 str로 저장
   cout << "딸기 -> " << (LPCTSTR)str << endl;

 

  // map을 처음부터 끝까지 모두 출력
  POSITION pos = map.GetStartPosition(); // 나열된 map중 맨 처음 값을 return
  while(pos != NULL){
   CString strKey, strValue;
   map.GetNextAssoc(pos, strKey, strValue);
   cout << (LPCTSTR)strKey << "->" << (LPCTSTR)strValue << endl;
  }