我做了一个项目,我只读了 1 行 20 个字符,并将这些字符与答案键进行比较,并根据他们在文件中输入的内容输出正确的数量和错误的数量。我下面的代码显示了 .dat 文件中只有一行 20 个字符的情况。我想做同样的事情,但每行 7 行 20 个字符。我不确定要写什么来分隔 7 行并将它们分别与正确答案进行比较。
char letter;
int index = 0;
while (inData >> letter) // takes the character from each array from the file
{
studentAns[index] = letter;
index++; // takes the 20 characters from the file
}
我尝试在循环外部和内部添加更多变量,但输出没有显示任何内容。比如这个。
# Correct | # Incorrect
-----------------------
0 | 20
-----------------------
You failed!
char letter;
char letter2;
int index = 0;
int index2 = 0;
while (inData >> letter) // takes the character from each array from the file
{
studentAns[index] = letter;
index++; // takes the 20 characters from the file
while (inData >> letter2)
{
studentAns2[index2] = letter2;
index2++;
}
}