![]() |
![]() |
![]() |
![]() |
![]() |
|
Thus, you can have your main program ask for a file name, accept
one, open it, check to be sure it is open, and pass the resulting input
stream on to do_analysis, over and over, as follows:
main ( ) {
// Read file name and call analysis function repeatedly:
while (1) {
cout << "Please type the name of a train file." << endl << ": ";
cin >> input_buffer;
// Open:
ifstream car_stream (input_buffer);
// Check:
if (!car_stream) {cout << "No such file." << endl; return 0;}
// Analyze:
do_analysis (car_stream);
// Close
car_stream.close ( );
}
}