C++ 从文件读取数据时出现奇怪的符号?

C++ 从文件读取数据时出现奇怪的符号?,c++,arrays,text,output,C++,Arrays,Text,Output,我有一个程序,可以从两个单独的文本文件中获取数据,将它们放入数组中,相互比较,并输出特定的结果。然而,当我从文件中读取数据并试图显示数据时,在它最终显示文本文件中的所有数据之前,我得到了很多奇怪的符号。这是代码 // Ch07-Exam Grader.cpp : Defines the entry point for the console application. // //Libraries #include "stdafx.h" #include <iostream> #in

我有一个程序,可以从两个单独的文本文件中获取数据,将它们放入数组中,相互比较,并输出特定的结果。然而,当我从文件中读取数据并试图显示数据时,在它最终显示文本文件中的所有数据之前,我得到了很多奇怪的符号。这是代码

// Ch07-Exam Grader.cpp : Defines the entry point for the console application.
//

//Libraries
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

//Prototypes
void initialization(void);
void proccess(void);
void eoj(void);
void writeIt(void);
void readIt(void);
void calculate(void);

//Global Variables
ifstream student;
ifstream correct;


int main()
{
initialization();

return 0;
}

//This function opens the files and calls the function to send the data into the array
void initialization (void){
correct.open("CorrectAnswers.txt");
readIt();

student.open("StudentAnswers.txt");
readIt();

}
void proccess (char c[], char s[], int length){

int correctCount = 0;
int incorrectCount = 0;

for (int i = 0; i< length; i++){
    if (s[i] == c[i]){
        correctCount = correctCount + 1;
    } else {
        incorrectCount = incorrectCount + 1;
    }
}

}
void eoj (void){

}
void writeIt (void){

}

//This function will take the data and place it into seperate arrays
void readIt (void){
char studentArray[20]; //Array to hold the student answers
char correctArray[20]; //Array to hold the correct answers

//Loops to place data to seperate arrays
for (int i = 0; !correct.eof(); i++){
    correct >> correctArray[i];
}
for (int j = 0; !student.eof(); j++){
    student >> studentArray[j];
}
    for (int i = 0; i < 20; i++){
    cout << studentArray[i] <<endl;
}
proccess(correctArray, studentArray, 20);

}
void calculate (void){

}
//Ch07 Exam Grader.cpp:定义控制台应用程序的入口点。
//
//图书馆
#包括“stdafx.h”
#包括
#包括
#包括
#包括
使用名称空间std;
//原型
作废初始化(作废);
作废处理(作废);
无效eoj(无效);
无效写入(无效);
无效读取(无效);
无效计算(void);
//全局变量
ifstream学生;
如果流正确;
int main()
{
初始化();
返回0;
}
//此函数打开文件并调用函数将数据发送到阵列中
void初始化(void){
打开(“CorrectAnswers.txt”);
readIt();
student.open(“StudentAnswers.txt”);
readIt();
}
无效进程(字符c[],字符s[],整数长度){
int correctCount=0;
int incorrectCount=0;
for(int i=0;i>更正数组[i];
}
对于(int j=0;!student.eof();j++){
学生>>学生阵列[j];
}
对于(int i=0;i<20;i++){

cout为什么在initialization()函数中调用readIt()两次?看起来readIt()希望两个文件都是打开的,但是打开第一个文件,调用readIt(),打开第二个文件,调用readIt()再次说明。可能是此缺陷问题的原因吗?

显示至少一部分输入文件…并请使用所有警告编译并学习使用调试器。
readIt()
读取
正确的
学生的
,但您在打开
学生
之前调用了它。这是一个简单的错误。非常感谢您的帮助。我已经修复了它。它是。我已经修复了。非常感谢