텍스트 파일에서 텍스트를 읽었지만 eof에 도달하지 않아 무한 루프가 발생합니다.ifstream (cpp)을 사용하여 eof에 도달하지 마십시오
는 여기에 내가 한 줄을 처리 내가 addStudents를 호출 루프의
static ifstream inF;
inF.open(file,ifstream::in);
cin.rdbuf(inF.rdbuf());
while (inF.good() && !inF.eof())
{
addStudent(students);
}
if (inF.is_open())
{
inF.close();
inF.clear();
}
모든 반복을
을 쓴거야. 그게 잘 작동 해. 기본적으로 나는 D의 형태로 라인을 RAD 98 76.5 66 45 (아마도) 12000 여기에 코드입니다 : (무효 반환) 내가 루프가 계속 실행 파일의 끝 부분에 도착static void addStudent(vector<Student*> students)
{
char institution;
unsigned short id;
double gAverage, pGrade, salary;
cin >> institution;
switch (institution)
{
case ALICE:
cin >> id >> gAverage >> salary;
students.push_back(new Student(institution,id,gAverage,salary));
return;
case BOB:
cin >> id >> gAverage >> salary;
students.push_back(new Student(institution,id,gAverage,salary));
return;
case COLIN:
cin >> id >> gAverage >> pGrade >> salary;
students.push_back(new CollegeStudent(institution,id,gAverage,pGrade,salary));
return;
case DANNY:
cin >> id >> gAverage >> pGrade >> salary;
students.push_back(new CollegeStudent(institution,id,gAverage,pGrade,salary));
return;
}
}
및 addStudents 아무것도하지 않는다. 어떤 아이디어가 필요한가? 감사합니다.
'addStudent'에 대한 코드를 게시하십시오. –
또한 addStudents를 볼 필요가 있습니다. 원래 ifstream의 위치를 늘리지는 않을 것입니다. 항상 시작 부분에 있으며 항상 good() 및! eof()에 대해 true를 반환합니다. – Will