title: Repeated value at the end of the file
body: <p>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:-</p>
  
  <pre><code>int main(void)
  {
      string filename;
      int grades;
      cout&lt;&lt;"Enter the filename:"&lt;&lt;endl;
      getline(cin,filename);
      ifstream inFile(filename.c_str(),ios::in);
      if(!inFile){
          cout&lt;&lt;"File does not exist."&lt;&lt;endl;
          exit(1);
      }
      while(!inFile.eof())
      {
          inFile&gt;&gt;grades;
          cout&lt;&lt;grades&lt;&lt;endl;
      }
      inFile.close();
      return 0;
  }
  </code></pre>
  
  <p>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.</p>