#20 [c++] map

정상준·2022년 11월 26일
0

c++

목록 보기
16/25

📝 Map

  • 특징
    • ('키', '값')의 쌍을 원소로 저장하는 제네릭 컨테이너
  • '키'로 '값'을 검색
  • 많은 응용에서 필요함
  • #include <<"map">>필요

#include <iostream>
#include <map>
#include <string>

using namespace std;

/*
사전의 단어 갯수3
찾고 싶은 단어>>aplle
없음
찾고 싶은 단어>>apple
사과
찾고 싶은 단어>>love
사랑
찾고 싶은 단어>>exit
종료합니다..
*/


int main() {
	map<string, string> dic;
	dic.insert(make_pair("love", "사랑"));
	dic.insert(make_pair("apple", "사과"));
	dic["cherry"] = "체리";
	cout << "사전의 단어 갯수" << dic.size() << endl;
	string eng;
	while (true)
	{
		cout << "찾고 싶은 단어>>";
		getline(cin, eng);
		if (eng == "exit") { break; }

		if (dic.find(eng) == dic.end())
			cout << "없음" << endl;
		else
			cout << dic[eng] << endl;
	}
	cout << "종료합니다..";
}
profile
안드로이드개발자

0개의 댓글