CÓDIGO A 'RCIT = std :: vector <_Tp, _Alloc> :: rend() con _TP = int, _Alloc = std :: asignador!':error iterador inverso: no puede competir con 'operador! =' En
vector<int>::const_reverse_iterator rcit;
vector<int>::const_reverse_iterator tit=v.rend();
for(rcit = v.rbegin(); rcit != tit; ++rcit)
cout << *rcit << " ";
CÓDIGO B:
vector<int>::const_reverse_iterator rcit;
for(rcit = v.rbegin(); rcit != v.rend(); ++rcit)
cout << *rcit << " ";
CÓDIGO a funciona bien, pero ¿por qué CÓDIGO B throughs de error:!
DEV C++ \ vector_test.cpp no puede competir con 'operador! =' en 'RCIT = std :: vecto r < _Tp, _Alloc> :: rend() con _Tp = int, _Alloc = std :: allocator '.
Este es el programa que estaba tratando de escribir.
#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;
}
Publique un código más ... el código que ha publicado no es el problema ... – Nawaz
bien, solo una minuto – munish
su código compila para mí muy bien con mingw en windows – Vusak