728x90
탐색방법
- index로 접근할 수 없고 iterator로 접근
- 시작 : begin( ), 끝 : end( )
- key : iter->first, value : iter->second
- 반복문 사용 시 auto 활용 or pair< key_type, value_type > 사용
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>//multimap은 중복 key를 허용
using namespace std;
int main(void)
{
multimap<int, int> mm;
multimap<string, string>multimapstr;
multimapstr.insert(make_pair("0","cry"));
multimapstr.insert(make_pair("0", "343"));
for (pair<string, string> tempmap : multimapstr) {
cout << tempmap.first << ":" << tempmap.second << " ";
}
return 0;
}
728x90
'C++ > c++' 카테고리의 다른 글
[STL] unordered_map과 make_pair 같이 쓰기 (0) | 2022.01.04 |
---|---|
[STL] 이중 Vector : 예시 vector<vector<string>>, 코드첨부 (0) | 2022.01.04 |
c++ vector /pair / sort 사용 예제 (0) | 2021.11.17 |
[c++] std::array / try catch / auto element 연습 예제 (0) | 2021.09.21 |
[c++] 코딩테스트에서 ios::sync_with_stdio; cin.tie(0); 를 쓰면 좋은 이유 (0) | 2021.09.19 |