This topic has not yet been rated - Rate this topic

# operator+ (<iterator>)

Visual Studio 2013

Adds an offset to an iterator and returns a move_iterator or a reverse_iterator addressing the inserted element at the new offset position.

```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

The number of positions the const move_iterator or const reverse_iterator is to be offset.

_Right

The iterator to be offset.

Returns the sum _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;
}
```
```The initial vector vec is: ( 0 2 4 6 8 10 ).
The iterator rVPOS1 initially points to the first element
in the reversed sequence: 10.
The iterator rVPOS1 now points to the fifth element
in the reversed sequence: 2.```

Namespace: std

#### Reference

(1500 characters remaining)