operator- (<iterator>)
다른 한 반복기를 빼고 차이 반환 합니다.
template<class RandomIterator1, class RandomIterator2>
Tdiff operator-(
const move_iterator<RandomIterator1>& _Left,
const move_iterator<RandomIterator2>& _Right
);
template<class RandomIterator1, class RandomIterator2>
Tdiff operator-(
const reverse_iterator<RandomIterator1>& _Left,
const reverse_iterator<RandomIterator2>& _Right
);
매개 변수
_Left
반복기입니다._Right
반복기입니다.
반환 값
두 반복기 사이의 차이.
설명
첫 번째 서식 연산자 반환 _Left.base() - _Right.base().
두 번째 템플릿 연산자 반환 _Right.current - _Left.current.
Tdiff반환 된 식 유형에 따라 결정 됩니다.그렇지 않으면 RandomIterator1::difference_type입니다.
예제
// iterator_op_sub.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for (i = 0 ; i < 6 ; ++i )
{
vec.push_back ( 2 * i );
}
vector <int>::iterator vIter;
cout << "The initial vector vec is: ( ";
for ( vIter = vec.begin( ) ; vIter != vec.end( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
vector <int>::reverse_iterator rVPOS1 = vec.rbegin ( ),
rVPOS2 = vec.rbegin ( );
cout << "The iterators rVPOS1 & rVPOS2 initially point to "
<< "the first element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
for (i = 1; i < 5; ++i)
{
rVPOS2++;
}
cout << "The iterator rVPOS2 now points to the fifth "
<< "element\n in the reversed sequence: "
<< *rVPOS2 << "." << endl;
vector<int>::difference_type diff = rVPOS2 - rVPOS1;
cout << "The difference: rVPOS2 - rVPOS1= "
<< diff << "." << endl;
}
요구 사항
헤더: <iterator>
네임 스페이스: std