I need help with properly reading and storing some characters from a text file into my array. I got something going but when I run it, the output shows only the first 10 characters.
The text file I am using is the following...
B
D
D
C
B
C
A
C
C
D
A
B
A
B
C
B
D
B
C
D
But like I said when I run the program. It only displays the first 10 letters from that text file. That is precisely where I am lost and need help. Thanks.
Each character in the input file is on a separate line. This inFile.get(write2line) first reads the alphabetic character, the next time it reads the newline character '\n', then the next letter, then the next newline and so on.
In order to skip the newline (or other whitespace), use formatted input inFile >> instead of inFile.get().
1 2 3 4 5 6 7 8 9 10 11
// first read the file
for (int x = 0; x < numofQ; x++)
{
inFile >> CorrectAnswers[x];
}
// then display array contents
for (int x = 0; x < numofQ; x++)
{
cout << CorrectAnswers[x] << '\n';
}