operator+ (<iterator>)
Ajoute un offset à un itérateur et retourne move_iterator ou reverse_iterator adressant l'élément inséré au nouveau décalage de l'offset.
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
);
Paramètres
_Off
Le nombre de caractères le move_iterator const ou le reverse_iterator const doit être décalé._Right
l'itérateur à compenser.
Valeur de retour
Retourne la somme _Right + _Off.
Exemple
// 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;
}
Configuration requise
en-tête : <iterator>
l'espace de noms : DST