map_begin
map_begin (std::map::begin — 시작 이터레이터)
std::map의 첫 번째 원소를 가리키는 이터레이터를 반환하는 멤버 함수예요. 컨테이너가 비어 있으면 end()와 같아요.
출처: cppreference
본문
시그니처는 다음과 같아요.
iterator begin(); // (1)
const_iterator begin() const; // (2)
const_iterator cbegin() const noexcept; // (3) (since C++11)
map의 첫 번째 원소를 가리키는 이터레이터를 반환해요. map이 비어 있으면 반환된 이터레이터는 end()와 같아요.
반환값
첫 번째 원소를 가리키는 이터레이터.
복잡도
상수(constant)예요.
예제
#include <iostream>
#include <map>
int main()
{
std::map<int, char> m{{1, 'a'}, {2, 'b'}, {3, 'c'}};
for (auto it = m.begin(); it != m.end(); ++it)
std::cout << it->first << ':' << it->second << ' '; // 1:a 2:b 3:c
}