Here is a program I wrote for an assignment, there is an error that I tried for days to fix but with no luck. I know where it is but I dont know why the error shows up. Its a grading sheet program
while(!file.eof()) //While it is not the end of the file...
{
cout<<setw(5)<<ID; //Display ID
cout<<setw(20)<<NAME; //Display First name
cout<<setw(20)<<GRADE<<endl; //Display Grade
file>>ID>>NAME>>GRADE; //Reads from the data file (ERROR IS AT THIS LINE)
}
file.close(); //Closes the file
system("pause");
return 0;
}
I'm not familiar with while(file.good())
And, I tried unrolling, error still exists. I think its a variable error as because I think I got all my streams in right. I still am unable to fix it
you do not use file.seak(std::ios::begin) between the read and write. Nor do you open the file do write operations, then close it and then reopen it. Unless you know how to manipulate the file pointer, it is never a good idea to mess with the file pointer in the way you have.