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
类型 迭代器对象。_Right
类型 迭代器对象。
返回值
true,则迭代器对象不相等;false,则迭代器对象相等。
备注
如果解决这些问题在容器元素相同的元素,一个迭代器对象相等到另一个。 如果对不同元素的两个迭代器指向容器中,则它们不相等。
示例
// 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;
}
要求
头文件: <iterator>
命名空间: std