共用方式為


operator+ (<iterator>)

將 Iterator 的位移並傳回 move_iteratorreverse_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
    要位移的 Iterator。

傳回值

傳回總和 _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;
}
  

需求

標頭:<迭代器>

命名空間: std

請參閱

參考

標準樣板程式庫