I've been trying to read in values from a text file into 2 arrays, however I end up with nothing inside my names and scores arrays. Here's what I have:
const int size = 6;
int names[size] = { 0 };
int scores[size] = { 0 };
int name;
ifstream inputFile;
inputFile.open("input.txt"); //opens up textfile
inputFile >> name;
while (!inputFile.eof()){
inputFile >> names[x] >> scores[x];
cout << names[x] << scores[x];
x++;
}
input.txt
6
Alice 50
Bob 100
Cathryn 75
Don 90
Emily 80
Flora 60
George 95
name is picking up a value of 6, but names and scores are picking up nothing. Any ideas about what's wrong?
namesandscoresarray.cout << inputFileinstead and see if the file is actually being read.sizea constant?