title: How to detect an empty file in C++?
body: <p>I am trying to use eof and peek but both seems not to give me the right answer.</p>
  
  <pre><code>if (inputFile.fail()) //check for file open failure
  {
      cout &lt;&lt; "Error opening file" &lt;&lt; endl;
      cout &lt;&lt; "Note that the program will halt" &lt;&lt; endl;//error prompt
  }
  
  else if (inputFile.eof())
  {
      cout &lt;&lt; "File is empty" &lt;&lt; endl;
      cout &lt;&lt; "Note that program will halt" &lt;&lt; endl; // error prompt
  }
  else
  {
      //run the file
  }
  </code></pre>
  
  <p>it cannot detect any empty file using this method. If i use inputFile.peek instead of eof it would make my good files as empty files.</p>