Ошибка обратного итератора: нет совпадения для 'operator! =' В 'rcit! = Std :: vector <_Tp, _Alloc> :: rend () с _Tp = int, _Alloc = std :: allocator '

CODE A:

vector< int >::const_reverse_iterator rcit;
vector< int >::const_reverse_iterator tit=v.rend();
for(rcit = v.rbegin(); rcit != tit; ++rcit)
cout << *rcit << " ";

CODE B:

vector< int >::const_reverse_iterator rcit;
for(rcit = v.rbegin(); rcit != v.rend(); ++rcit)
cout << *rcit << " ";

CODE A works fine but why does CODE B throughs error :

DEV C++\vector_test.cpp no match for 'operator!=' in 'rcit != std::vector<_Tp, _Alloc>::rend() with _Tp = int, _Alloc = std::allocator'.

This is the program I was trying to write.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using namespace std;
#include <vector>
using std::vector;
template< typename T > void printVector( const vector< T > &v);

template< typename T > 
void printVector( const vector< T > &v)
{
             typename vector< T >::const_iterator cit;
             for(cit = v.begin(); cit != v.end(); ++cit)
             cout << *cit << " ";
}

int main()
{
    int number;
    vector< int > v;

    cout << "Initial size of the vector : " << v.size()
         << " and capacity : " << v.capacity() << endl;
    for(int i=0; i < 3; i++)
    {
            cout << "Enter number : ";
            cin >> number;
            v.push_back(number);
    }
    cout << "Now size of the vector : " << v.size()
         << "and capacity : " << v.capacity() << endl;

    cout << "output vector using iterator notation " << endl; 
    printVector(v);

    cout << "Reverse of output ";
    vector< int >::const_reverse_iterator rcit;
    for(rcit = v.rbegin(); v.rend() != rcit ; ++rcit)
    cout << *rcit << " ";
    cin.ignore(numeric_limits< streamsize >::max(), '\n'); 
    cin.get();
return 0;
}
5
задан munish 6 May 2011 в 05:34
поделиться