I apologize if this has been answered already, I tried searching and couldn't figure out why this isn't working.
I am writing a program to read from a file, the file contains lines of one name followed by 5 integers. I am trying to read the name into one string array and then read the 5 integers into another array. When I run my code the first name and first 5 integers are read as expected, but then when the loop continues, nothing else is read into the arrays.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int row, col, average, students = 0;
string storage;
string names[15];
double test[15][5];
double grade[15];
ifstream inFile;
ofstream outFile;
inFile.open("testScores.txt");
outFile.open("averages.out");
for (students; !inFile.eof(); students++)
{
//getline(inFile, storage, '\n');
inFile >> names[students];
for (col = 0; col <= 5; col++)
{
inFile >> test[students][col];
}
inFile.ignore('\n');
}
I know that using namespace std is frowned upon, but that is how my teacher wants us to complete the code. I tried adding an ignore in to skip to the next line in the input, but that hasn't seemed to work. I also tried using a temporary storage string using getline, but wasn't sure that was the best way to go about it. Any help would be greatly appreciated. Thank you
input file-
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63