[C++] advance
1. advance
- iterator 헤더에 정의
- iterator에 n개의 요소가 주어질 때 특정 index를 찾음
#include <iostream>
#include <iterator>
#include <vector>
int main()
{
std::vector<int> v{ 3, 1, 4 };
auto vi = v.begin();
std::advance(vi, 2);
std::cout << *vi << ' '; // 4
vi = v.end();
std::advance(vi, -2);
std::cout << *vi << '\n'; // 1
}
참고
This is personal diary for study documents.
Please comment if I'm wrong or missing something else 😄.
댓글남기기