求解一个关于 eof() 函数的问题
我写得学生管理系统的构造函数,总是多读一个空的Student信息出来,有个和我一样问题的他把file.read((char *)End->name,15)加上了break,就可以了,这是为什么啊?难道eof()判断出问题了?ManageStu::ManageStu()
{
Head = new Student;
End = Head->Next = NULL;
Choose[0] = &ManageStu::Print;
Choose[1] = &ManageStu::AddStu;
Choose[2] = &ManageStu::Modifiy;
Choose[3] = &ManageStu::Search;
Choose[4] = &ManageStu::DelStu;
file.open("e:\\Student.txt",ios_base::in|ios_base::binary);
if(!file);
else
{
Head->Next = new Student;
End = Head->Next;
Student *p = End;
file.seekg(0);
while(!file.eof())
{
if(!file.read((char *)End->name,15))
break;
file.read((char *)End->num,15);
file.read((char *)&End->usual_score,sizeof(float));
file.read((char *)&End->test_score,sizeof(float));
End->Next = new Student;
p = End;
End = End->Next;
}
p->Next = NULL;
delete End;
End = p;
file.clear() ;
}
file.close();
}