As part of a larger assignment I have to create a method in a class that can read five lines of data then put that data into a dynamically created object. I am not sure how to go about getting the five lines of data separately into the object. The code should help to explain better but it does not work as desired. If someone can spot my mistakes please let me know. If you can help me it would be greatly appreciated. Also every five lines read I create a new object, until no lines are left. How would I know if any lines are left? Once again any help would be appreciated thank - you for your time.
inline void readFromFile(const string& fileName){
string title;
string category;
unsigned int runningTime;
unsigned int yearOfRelease;
double price;
ifstream myReadFile;
myReadFile.open(fileName);
while( myReadFile )
{
myReadFile>>title;
myReadFile >> category;
myReadFile >> runningTime;
myReadFile >> yearOfRelease;
myReadFile >> price;
v.push_back(new DVD(title,category,runningTime,yearOfRelease,price));
}
myReadFile.close();
for(unsigned int i = 0; i < v.size(); i++){
cout << *v.at(i) << endl;
}
}