title: ifstream::read keeps returning incorrect value
body: <p>I am currently working my way through teaching myself how to work with files in c++, and I am having a good bit of difficulty extracting binary information from files.</p>
  
  <p>My code:</p>
  
  <pre><code>std::string targetFile = "simplehashingfile.txt";
  const char* filename = targetFile.c_str();
  std::ifstream file;
  
  file.open( filename, std::ios::binary | std::ios::in );
  file.seekg(0, std::ios::end);  //  go to end of file
  std::streamsize size = file.tellg();  //  get size of file
  
  std::vector&lt;char&gt; buffer(size);  //  create vector of file size bytes
  
  file.read(buffer.data(), size);  //  read file into buffer vector
  int totalread = file.gcount();
  
  //  Check that data was read
  std::cout&lt;&lt;"total read: " &lt;&lt; totalread &lt;&lt; std::endl;
  
  
  //  check buffer:  
  std::cout&lt;&lt;"from buffer vector: "&lt;&lt;std::endl;
  for (int i=0; i&lt;size; i++){
      std::cout &lt;&lt; buffer[i] &lt;&lt; std::endl;
  }
  std::cout&lt;&lt;"\n\n";
  </code></pre>
  
  <p>The "simplehashingfile.txt" file only contains 50 bytes of normal text.  The size is correctly determined to be 50 bytes, but gcount returns 0 chars read, and the buffer output is (understandably from the gcount) a 50 line list of nothing.</p>
  
  <p>For the life of me I cannot figure out where I went wrong!  I made this test code earlier:</p>
  
  <pre><code>//  Writing binary to file
  std::ofstream ofile;
  ofile.open("testbinary", std::ios::out | std::ios::binary);
  
  uint32_t bytes4 = 0x7FFFFFFF;  //  max 32-bit value
  uint32_t bytes8 = 0x12345678;  //  some 32-bit value
  
  
  ofile.write( (char*)&amp;bytes4 , 4 );
  ofile.write( (char*)&amp;bytes8, 4 );
  
  ofile.close();
  
  
  
  //  Reading from file
  std::ifstream ifile;
  ifile.open("testbinary", std::ios::out | std::ios::binary);
  
  uint32_t reading;  //  variable to read data 
  uint32_t reading2;
  
  ifile.read( (char*)&amp;reading, 4 );
  ifile.read( (char*)&amp;reading2, 4 );
  
  std::cout &lt;&lt; "The file contains:  " &lt;&lt; std::hex &lt;&lt; reading &lt;&lt; std::endl;
  std::cout&lt;&lt;"next 4 bytes:  "&lt;&lt; std::hex &lt;&lt; reading2 &lt;&lt; std::endl;
  </code></pre>
  
  <p>And that test code wrote and read perfectly.  Any idea what I am doing wrong?  Thank you to anyone who can point me in the right direction!</p>