共用方式為


operator!= (<iterator>)

測試運算子左邊的迭代器物件是否不等於右邊的迭代器物件。

template<class RandomIterator> 
   bool operator!=( 
      const reverse_iterator<RandomIterator>& _Left, 
      const reverse_iterator<RandomIterator>& _Right 
   ); 
template<class Type, class CharType, class Traits, class Distance> 
   bool operator!=( 
      const istream_iterator<Type, CharType, Traits, Distance>& _Left, 
      const istream_iterator<Type, CharType, Traits, Distance>& _Right 
   ); 
template<class CharType, class Tr> 
   bool operator!=( 
      const istreambuf_iterator<CharType, Traits>& _Left, 
      const istreambuf_iterator<CharType, Traits>& _Right 
);

參數

  • _Left
    型別 iterator物件。

  • _Right
    型別 iterator物件。

傳回值

true Iterator,如果物件不相等; false ,如果 Iterator 物件。

備註

如果它們解決容器,的相同項目的 Iterator 物件等於另一個。 如果對不同項目的兩個 Iterator 指向容器,則它們相等。

範例

// iterator_op_ne.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;
   int i;

   vector<int> vec;
   for ( i = 1 ; i < 9 ; ++i )  
   {
      vec.push_back ( i );
   }
   
   vector <int>::iterator vIter;

   cout << "The vector vec is: ( ";
   for ( vIter = vec.begin( ) ; vIter != vec.end( ); vIter++ )
      cout << *vIter << " ";
   cout << ")." << endl;

   // Initializing reverse_iterators to the last element
   vector <int>::reverse_iterator rVPOS1 = vec.rbegin ( ), 
           rVPOS2 = vec.rbegin ( );
   
   cout << "The iterator rVPOS1 initially points to the first "
        << "element\n in the reversed sequence: "
        << *rVPOS1 << "." << endl;

   if ( rVPOS1 != rVPOS2 )
      cout << "The iterators are not equal." << endl;
   else
      cout << "The iterators are equal." << endl;

   rVPOS1++;
   cout << "The iterator rVPOS1 now points to the second "
        << "element\n in the reversed sequence: "
        << *rVPOS1 << "." << endl;

   if ( rVPOS1 != rVPOS2 )
      cout << "The iterators are not equal." << endl;
   else
      cout << "The iterators are equal." << endl;
}
  

需求

標頭:<迭代器>

命名空間: std

請參閱

參考

標準樣板程式庫