My code is supposed to read a file and from the information on that file create objects of class Movie and store them in a vector, How can I print those objects now that they are in the vector?
void Movie::loadFile(string file)
{
ifstream inFile;
inFile.open(file+".txt");
try {
if (!inFile)
throw "UNABLE TO OPEN FILE";
}catch (const char* msg)
{
cerr << msg << endl;
exit(1);
}
while (inFile.good())
{
getline(inFile, id, ',');
getline(inFile, name, ',');
getline(inFile, tim, ',');
getline(inFile, gen, ',');
getline(inFile, rate, '\n');
mov.push_back(new Movie(id, name, tim, gen, rate));
}
inFile.close();
cout<<endl;
}
I have tried to do it by overloading an operator but I get the errors
error: 'std::vector<Movie*> Movie::mov' is protected within this context
error: 'ostream_iterator' was not declared in this scope
error: expected primary-expression before '>' token
ostream &operator <<(ostream& salida, const Movie& print)
{
salida << print.id << endl;
copy(print.mov.begin(), print.mov.end(), ostream_iterator<Video>(salida, " "));
return salida;
}
I would really aprecciate the help :).