프로그래밍/C++

C++ std::begin, std::end, iterator

comflex 2022. 2. 19. 10:11
728x90
반응형

std::begin, std::end, iterator

데이터 타입에 맞는 iterator를 리턴한다.

목차

  • begin
  • end

begin

처음 원소를 가르키는 iterator를 리턴한다.

end

마지막 원소 다음을 가리키는 iterator를 리턴한다.

  • 코드
#include <iostream>
#include <vector>
#include <iterator>

using namespace std;

int main()
{
  vector<int> v = { 1, 2, 3 };
  cout << *begin(v) << endl;
  cout << *v.begin() << endl;
  cout << v[0] << endl;  
}
  • 출력
1
1
1
728x90
반응형