Vector class and Iterator
what seems to be wrong with my program
conversion from '__gnu_cxx::__normal_iterator<content*, std::vector<content, std::allocator<content> > >' to non-scalar type '__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >' requested|
|
this is the output
and I can make nothing of it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class content
{
private:
string movieName;
string releaseDate;
public:
//constructors
content();
friend ostream& operator <<(ostream& out ,const content& obj);
friend istream& operator >>(istream& in ,content& obj);
friend void displayWelcome();
};
content::content()
{
movieName = " ";
releaseDate = " ";
}
ostream& operator <<(ostream& out ,const content& obj)
{
out << "The name of movie is : ";
out << obj.movieName;
out << endl;
out << "released on ";
out << obj.releaseDate;
out << endl << endl;
return out;
}
istream& operator >>(istream& in, content& obj )
{
cout << "Enter movie name (format The-Matrix-Revolutons) : ";
in >> obj.movieName;
cout << "Enter release date (just the year of release eg 1996) : ";
in >> obj.releaseDate;
return in;
}
int main()
{
// content::displayWelcome();
content c1;
cin >> c1;
vector<content> v1;
v1.push_back(c1);
vector<int>::iterator iter= v1.begin();
cout << *iter;
return 0;
}
|
the error is in line
vector<int>::iterator iter= v1.begin();
Last edited on
You can't iterate a vector<content> with an iterator designed to iterate a vector<int>
alaa :)
thanks L B.
Topic archived. No new replies allowed.