title: Checking whether file contains only whitespace C++
body: <p>I am trying to read input from a file in C++, and I need to give an error message if there is no input. </p>
  
  <p>This statement works if the file is completely empty:</p>
  
  <pre><code>if (f.peek() == std::ifstream::traits_type::eof()) return error("Empty file");
  </code></pre>
  
  <p>where error() is a simple function:</p>
  
  <pre><code>int error(string message){
     cerr &lt;&lt; "ERROR: " &lt;&lt; message &lt;&lt; "\n";
     return -1;
  }
  </code></pre>
  
  <p>How can I check for files that contain only whitespace so I can raise the same error? Such as 7 newlines?<br>
  My should continue executing normally if the file contains anything but only whitespace characters.</p>