Something doesn't make much sense.
I don't think you should be comparing the filename entered by the user with some fixed piece of text.
Instead, your program should attempt to open the file which the user specified, if it succeeds, proceed with the rest of the program. Otherwise output an error message and quit.
1 2 3 4 5 6 7 8 9 10 11 12
|
char filename[25];
cout << "Please enter the name of the input file.\nFilename: ";
cin >> filename;
ifstream input(filename);
if (!input)
{
cout << "Could not open file: " << filename << endl;
return 1;
}
|
if this is the contents of the input file:
6
Team A,3,13,0
Team B,15,1,1
team C,9,7,1
Team D,10,6,1
Team E,7,9,0
Team F,11,5,1 |
then this struct won't fit the data:
1 2 3 4 5 6
|
struct TeamList {
char namerino;
int winerino;
int losserino;
bool thePLAYOFFS;
};
|
"Team A" is a character string containing spaces.
It won't fit inside a single character
char namerino;
First read the int , read/ ignore the newline character.
allocate a dynamic array of TeamList objects.
Repeat that many times:
Reading each line of data will take multiple steps.
1. read the name (and discard the comma) (use getline).
2. read the integer.
3. read/ignore the comma.
4. read the integer.
5. read/ignore the comma.
6. read the bool.
7. check the file status is still ok
8. read/ignore newline character '\n'.
If the input file looked like this, things would be easier:
6
Team-A 3 13 0
Team-B 15 1 1
team-C 9 7 1
Team-D 10 6 1
Team-E 7 9 0
Team-F 11 5 1 |
(no commas, no need for getline)