[C++] map

hwee·2024년 1월 19일
0

c++문법

목록 보기
2/4
post-thumbnail

사용 목적

키가 전부 unique할 때, 'key-value'를 저장하는 자료구조가 필요할 때

헤더

#include <map>

map이 사용할 수 있는 함수들

map.find(키값)

if (m.find("Alice") != m.end()) {
	cout << "find" << endl;
}
else {
	cout << "not find" << endl;
}

erase(키값)

m.erase("Alice");

clear()

m.clear();  //모든 요소 삭제

insert({ket, value})

m.insert({"Cam", 300});
//insert를 사용하지 않고 m["Cam"]++;로 접근시 value는 
//자동으로 0으로 초기화되어 삽입되므로 연산결과 1이된다.

Reference
https://life-with-coding.tistory.com/305

profile
https://fuzzy-hose-356.notion.site/1ee34212ee2d42bdbb3c4a258a672612

0개의 댓글

관련 채용 정보