STL - hash_map - sample(2)

2017. 1. 4. 22:50IT-개발/C및C++

반응형


#include <iostream>

#include <hash_map>

using namespace std;

using namespace stdext;


// 게임 캐릭터

struct GameCharacter

{

GameCharacter() { }

GameCharacter( int CharCd, int Level, int Money )

{

_CharCd = CharCd;

_Level = Level;

_Money = Money;

}

int _CharCd; // 캐릭터코드

int _Level; // 레벨

int _Money; // 돈

};


void main()

{

hash_map<int, GameCharacter> Characters;

GameCharacter Character1(12, 7, 1000 );


Characters.insert(hash_map<int, GameCharacter>::value_type(12, Character1));

GameCharacter Character2(15, 20, 111000 );

Characters.insert(hash_map<int, GameCharacter>::value_type(15, Character2));

GameCharacter Character3(7, 34, 3345000 );

Characters.insert(hash_map<int, GameCharacter>::value_type(7, Character3));

GameCharacter Character4(14, 12, 112200 );

Characters.insert(hash_map<int, GameCharacter>::value_type(14, Character4));

GameCharacter Character5(25, 3, 5000 );

Characters.insert(hash_map<int, GameCharacter>::value_type(25, Character5));

hash_map<int, GameCharacter>::iterator Iter1;

cout << "저장한 캐릭터 리스트" << endl;

for( Iter1 = Characters.begin(); Iter1 != Characters.end(); ++Iter1 )

{

cout << "캐릭터 코드 : " << Iter1->second._CharCd << " | 레벨 : " <<

Iter1->second._Level << "| 가짂 돈 : " << Iter1->second._Money << endl;

}

cout << endl;

cout << "lower_bound(14)" <<endl;

hash_map<int, GameCharacter>::iterator Iter = Characters.lower_bound(14);

while( Iter != Characters.end() )

{

cout << "캐릭터 코드 : " << Iter->second._CharCd << " | 레벨 : " <<

Iter->second._Level << "| 가짂 돈 : " << Iter->second._Money << endl;

++Iter;

}

cout << endl;

cout << "upper_bound(7)" <<endl;

Iter = Characters.upper_bound(7);

while( Iter != Characters.end() )

{

cout << "캐릭터 코드 : " << Iter->second._CharCd << " | 레벨 : " << Iter

>second._Level << "| 가짂 돈 : " << Iter->second._Money << endl;

++Iter;

}


}




'IT-개발 > C및C++' 카테고리의 다른 글

STL - map - sample(2)  (0) 2017.01.04
STL - map - sample(1)  (0) 2017.01.04
STL - hash_map - sample(1)  (0) 2017.01.04
STL - Deque - sample(1)  (0) 2017.01.04
STL - Deque  (0) 2017.01.04