Thursday 30 August 2018

c++ - Repeated value at the end of the file

I am writing a program to take input from a file and display it on the console. The problem is that the last entry is being repeated twice. The code is as follows:-



int main(void)
{

string filename;
int grades;
cout<<"Enter the filename:"< getline(cin,filename);
ifstream inFile(filename.c_str(),ios::in);
if(!inFile){
cout<<"File does not exist."< exit(1);
}
while(!inFile.eof())

{
inFile>>grades;
cout< }
inFile.close();
return 0;
}


Can you please help me in finding out the mistake? I have searched on the web and my code seems to be syntactically and logically correct.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...