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
位置的数量 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