#include
#include
#include
using namespace std;
ifstream inData;
ofstream outData;
string Answerstd;
string Answer;
void Checktheanswer(ifstream&,ofstream&,string&,string&);
int main ()
{
inData.open("exams.dat");
outData.open("scores.dat");
string Num;
inData>>Answerstd;
inData>>Num;
inData>>Answer;
Checktheanswer(inData,outData,Num,Answer);
outData.close();
return 0;
}
//*****************************************************************************************************
void Checktheanswer(ifstream& inData,ofstream& outData,string& Num,string& Answer)
{
while(inData)
{
if (Answer.length()==Answerstd.length())
{
int T; //计读取的次数
int I; //计答案的个数
int Mark; //成绩
T=0;
I=0;
Mark=0;
while (T<=4)
{
Mark=0;
I=0;
while (I<=20)
{
if (Answer.substr(I,1)!="a"&&Answer.substr(I,1)!="b"&&Answer.substr(I,1)!="c"&&Answer.substr(I,1)!="d"&&Answer.substr(I,1)!="e"&&Answer.substr(I,1)!="f")
{
cout<<"The answer is illigal,it must be a-f and All of them must be 20"<
}
else if (Answer.substr(I,1)==Answerstd.substr(I,1))
Mark=Mark+1;
I++;
}
outData<
inData>>Answer;
T++;
}
}
else
cout<<"The length of the answer is not correct !"<
inData>>Num;
inData>>Answer;
}
}
一个读取文件中学生答案与标准答案比对的程序,不放数据文件时一切正常,一放就出那个错误,另 学号 也就是NUM变量要读取的是一个7位的号码
求高人指点 非常急!在线等结果 谢谢