/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <fstream>
int main()
{
const std::string filename = "schedule.txt";
std::string test, movieName, movieTime, movieHall;
std::ifstream file (filename);
if (file.is_open()) {
while (file >> test) {
// At this point test is either "Title:" or a movie time
if (test == "Title:") {
// test is "Title:" so we need to save the movie title
std::getline(file, movieName);
std::cout << "\nMovie:" << movieName;
} else {
// test is a movie time so save that movie time and then read the movie hall
movieTime = test;
std::getline(file, movieHall);
std::cout << ", " << movieTime << movieHall;
}
}
file.close();
}
else
std::cout << "unable to open file";
return 0;
}
Title: Titanic
17:40 hall 1
19:20 hall 7
20:20 hall 1
Title: To Kill a Mockingbird
14:10 hall 3
15:50 hall 3
18:25 hall 8
20:30 hall 2
Title: The Silence of the Lambs
19:30 hall 5
20:50 hall 4
22:10 hall 3