I'm trying to complete an assignment for my intro to C++ class and I've reached an impasse! The program is supposed to be a VHS Video Manager, in which the movies are stored in structures. The movies are obtained from a .txt file in the source folder and consist of the title of the movie, as well as the year. After reading in the text file, the initial output should look like this:
Initializing Video Collection:
What file should I use? movies.txt
A New Hope (1977)
Empire Strikes Back (1980)
Flight of the Navigator (1986)
Goonies (1985)
Last Crusade (1989)
Raiders of the Lost Ark (1981)
Return of the Jedi (1983)
Temple of Doom (1984)
War Games (1983)
The videos are stored in a structure that looks like this:
struct Video
{
string title; //the name of the video
int year; // the year the movie was released
int stars; // a rating out of five stars - this will be zero until you set it
bool watched; // starts as false until you watch the movie and flip it to true
};
It seems that I don't know how to read in my file correctly, so that the title and year are placed in their respective array locations. Here is the function that I have for this purpose:
void initialize(Video video_array[tapes_max], Video data)
{
ifstream videofile;
videofile.open("movies.txt");
if(videofile.fail())
{
cout << "Could not open states file for reading!" << endl;
exit(1);
}
for(int i = 0; i < tapes_max; i++)
{
getline(videofile, video_array[i].title);
}
videofile.close();
for (int i = 0; i < tapes_max; i++)
{
cout << video_array[i].title << " " << video_array[i].year << endl;
}
cout << endl << endl;
}
Here is the link to the PDF that was assigned to me, maybe you guys can make better sense of it than I can? Thanks in advance for your help!
https://docs.google.com/open?id=0Bwr7dC-H4CCZUkkyUGNTRzRZdk0