728x90
반응형
#include<map>
#include<iostream>
using namespace std;
int main(){
map<string,int>m;
//삽입
m.insert({"happy",1});
m.insert({"new",2});
m.insert({"year!",3});
//삭제
m.erase("new");
//요소가 있는지 찾기 - find
auto item=m.find("happy");
if(item!=m.end()){ //요소가 있음
cout<<item->second;
}
else{ //요소가 없음
cout<<"요소 없음";
}
//출력
//1
}
728x90
반응형
'programming language > c++' 카테고리의 다른 글
[C++] set 삽입,삭제,순회하기 (0) | 2022.11.26 |
---|---|
[C++] 공백, 특정 문자(:/,-..) 기준 문자열 자르기 (0) | 2022.11.26 |
[C++] vector에서 특정원소 지우기 vector.erase() (0) | 2022.09.09 |