operator+ (<iterator>)
向迭代器的偏移量并返回 move_iterator 或 reverse_iterator 解决该插入的元素在新的偏移位置。
template<class RandomIterator, class Diff>
move_iterator<RandomIterator> operator+(
Diff _Off,
const move_iterator<RandomIterator>& _Right
);
template<class RandomIterator>
reverse_iterator<RandomIterator> operator+(
Diff _Off,
const reverse_iterator<RandomIterator>& _Right
);
参数
_Off
位置的数量const move_iterator或常数reverse_iterator是偏移量。_Right
是的迭代器偏移量。
返回值
返回总和 _Right + _Off。
示例
// iterator_op_insert.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 ( );
cout << "The iterator rVPOS1 initially points to "
<< "the first element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
vector<int>::difference_type diff = 4;
rVPOS1 = diff +rVPOS1;
cout << "The iterator rVPOS1 now points to the fifth "
<< "element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
}
要求
标头: <iterator>
命名空间: std