samedi 23 juillet 2016
printing vector elements error message
I'm a beginner in c++. The following simple program to push elements into vector and to display them while traversing, is not working correctly. Compiler says "Expression:vector iterator is not derrencable."
Can any one help me about this ??
#include <iostream>
#include<vector>
int main()
{
int n;
std::vector<int>x;
std::vector<int>::iterator it;
for (it = x.begin(); it != x.end(); ++it)
{
std::cout << "enter an element in the vector:" << "n";
std::cin >> n;
x.push_back(n);
std::cout << "vector:" << "n";
std::cout << *it;
}
return 0;
}
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire