title: C++ fstream and printing to terminal
body: <p>I've got a bit of code that I am trying to get to work. Basically I want to open a file and print the contents to the terminal. Right now I've just got a list (1-10) in a .txt file in the same folder as my .cpp file. </p>
  
  <pre><code>int main() {
    ifstream inFile;    
    inFile.open("numbers.txt");
  
    if( inFile.fail()) {    
      cout&lt;&lt;"Error opening file "&lt;&lt; endl;    
      return 0;
    }
  
    while(!(inFile.fail())) {
      int x;
      inFile &gt;&gt; x;
      cout&lt;&lt;x&lt;&lt; endl;
    }
  }
  </code></pre>
  
  <p>This is what I have so far and it works to open the file and print to the console. Only issue is, that it prints the last line of the file twice ( so it print 1-10 fine but prints 10 twice) I've stumped myself trying to figure this out. Any ideas?</p>
  
  <p>Thanks for helping me edit this!</p>