我正在尝试完成我的 C++ 课程介绍的作业,但我陷入了僵局!该程序应该是一个 VHS 视频管理器,其中电影存储在结构中。电影是从源文件夹中的 .txt 文件中获取的,包含电影的标题和年份。读入文本文件后,初始输出应如下所示:
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)
视频存储在如下结构中:
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
};
似乎我不知道如何正确读取我的文件,以便将标题和年份放置在它们各自的数组位置中。这是我为此目的而拥有的功能:
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;
}
这是分配给我的PDF的链接,也许你们能比我更好地理解它?在此先感谢您的帮助!
https://docs.google.com/open?id=0Bwr7dC-H4CCZUkkyUGNTRzRZdk0