title: Can't write the last part of a txt file to cout using ifstream
body: <p>The code below will print all of the text from the sample text file I'm using except for the last little snippet of it.  I think this has something to do with the eof or the byte size I'm using not working as I expect.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main(int argc, char* argv[]){
  int length;
  char* buffer;
  
  //get file stream and open local file.
  ifstream stream;
  stream.open("SampleFile.txt", ios::binary);
  stream.seekg(0, ios::end);
  length = stream.tellg();
  stream.seekg(0, ios::beg);
  
  //read stream 1024 bytes at a time until all bytes of file are used
  buffer = new char[1024];
  bool eof = false;
  while(!eof)
  {
      stream.read(buffer, 1024);
      cout.write(buffer, 1024);
      if(stream.eof())
          eof = true;
      //cout &lt;&lt; i &lt;&lt; endl;
      //cout.write(buffer, 1024);
  }
  
  stream.close();
  delete[] buffer;
  return 0;
  }
  </code></pre>
  
  <p>What am I missing?</p>