Thursday, August 30, 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

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...