reverse_iterator::operator
으로 주소가 지정 된 요소에서 참조 요소의 오프셋을 반환 된 reverse_iterator 지정 된 수의 위치.
reference operator[](
difference_type _Off
) const;
매개 변수
- _Off
오프셋은 reverse_iterator 주소입니다.
반환 값
참조 요소의 오프셋입니다.
설명
The operator returns *(*this + _Off).
예제
// reverse_iterator_ret_ref.cpp
// compile with: /EHsc
#include <iterator>
#include <algorithm>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for (i = 1 ; i < 6 ; ++i )
{
vec.push_back ( 2 * i );
}
vector <int>::iterator vIter;
cout << "The vector vec is: ( ";
for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++ )
cout << *vIter << " ";
cout << ")." << endl;
vector <int>::reverse_iterator rvIter;
cout << "The vector vec reversed is: ( ";
for ( rvIter = vec.rbegin( ) ; rvIter != vec.rend( ); rvIter++)
cout << *rvIter << " ";
cout << ")." << endl;
vector <int>::iterator pos;
pos = find ( vec.begin ( ), vec.end ( ), 8 );
reverse_iterator<vector<int>::iterator> rpos ( pos );
// Declare a difference type for a parameter
reverse_iterator<vector<int>::iterator>::difference_type diff = 2;
cout << "The iterator pos points to: " << *pos << "." << endl;
cout << "The iterator rpos points to: " << *rpos << "." << endl;
// Declare a reference return type & use operator[]
reverse_iterator<vector<int>::iterator>::reference refrpos = rpos [diff];
cout << "The iterator rpos now points to: " << refrpos << "." << endl;
}
요구 사항
헤더: <iterator>
네임 스페이스: std