본문 바로가기
프로그래밍 기록/stl

map

by hominic 2023. 12. 8.
728x90
반응형
반응형
#include <iostream>
#include <string>
#include <map>
using namespace std;


struct SProduct
{
string Name;
int Price;
} arPro[]={
{"고소미",500},{"카스",400},{"네카페",250},{"라면",450},
{"88라이트",1900},{"불티나",300},{"스타킹",700},{"김치",2000},
{"신문",500},{"비타500",500},{"비타1000",1000},{"왕틀이",900},
{"치즈샌드",200},{"위스퍼",800},{"콘텍600",600},{"페리오치약",2200},
{"모나미볼펜",90},{"까페라떼",990},{"밧데리",1000},{"파이",250},
};

void main()
{
map<string,int> mPro;
map<string,int>::iterator it;
int i;
string Name;

for (i=0;i<sizeof(arPro)/sizeof(arPro[0]);i++) {
mPro[arPro[i].Name]=arPro[i].Price;
}

for (;;) {
cout << "상품명을 입력하시오(끝낼때는 '끝'입력) : ";
cin >> Name;
if (Name=="끝") break;
it=mPro.find(Name);
if (it == mPro.end()) {
cout << "그런 제품은 없습니다." << endl;
} else {
cout << Name << "의 가격은 " << it->second << "입니다." << endl;
}
}
}
728x90
반응형

'프로그래밍 기록 > stl' 카테고리의 다른 글

itervector  (0) 2023.12.08
iterarray  (0) 2023.12.08
list  (0) 2023.12.08
pushback  (0) 2023.12.08
vector  (0) 2023.12.08

댓글