title: Why do characters in this file read in as negative character codes in C++ (VS2017)?
body: <p>I'm trying to compile and run the open source code for Alien vs Predator (2000). See <a href="https://app.assembla.com/spaces/avp_mod/git/source" rel="nofollow noreferrer">https://app.assembla.com/spaces/avp_mod/git/source</a>. The level map data is stored in .RIF files, which are compressed. The first thing on each level load is to read in the data from the file before de-compressing it. In VS 2017, reading the file truncates after a certain number of character reads because it starts pulling in negative character codes (-44, for example). This is using </p>
  
  <p>std::ifstream infile;<br>
  inFile.open(file_name, std::ios::in | std::ios::binary | std::ios::ate);</p>
  
  <p>Not certain it matters, but the last character it successfully pulls in is a null (\0). After that, all values are negative. Any idea how to read this file correctly? I can provide more information if needed.</p>
  
  <p>I've also tried reading each character in one at a time, which is how I determined that the negatives were being pulled in.</p>
  
  <p><strong>Update</strong>: original code referenced in my comment below. On last line, "buffer" is filled with characters up to the point where the negative values begin to come in. This code, I assume, worked correctly as written in the original compiler (VS2010, I believe).</p>
  
  <p><code>unsigned long bytes_read;  <br/>char * buffer;  <br/>char * buffer_ptr;  <br/>char id_buffer[9];  <br/>HANDLE rif_file = CreateFileA(file_name, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0);  <br/>DWORD file_size = GetFileSize (rif_file, NULL);   <br/> if (!ReadFile(rif_file, id_buffer, 8, &amp;bytes_read, 0)) {  <br/> CloseHandle(rif_file);  <br/> return 0;  <br/> }  <br/> buffer = new char[file_size];   <br/>if (!ReadFile(rif_file, buffer + 8, (file_size - 8), &amp;bytes_read, 0))</code></p>
  
  <p><strong>Update 2:</strong> Link to one of the rif files: <a href="https://drive.google.com/open?id=18BJR_6CkeHPU25u1DY6RGQQVWmR-kGdP" rel="nofollow noreferrer">https://drive.google.com/open?id=18BJR_6CkeHPU25u1DY6RGQQVWmR-kGdP</a></p>
  
  <p><strong>Update 3:</strong> my test code
  <code>  const char * file_name = "E3demoSP.RIF";  <br/>std::ifstream inFile;  <br/>size_t size = 0;  <br/>inFile.open(file_name, std::ios::in | std::ios::binary);  <br/>char* oData = 0;  <br/>char ch;  <br/>inFile.seekg(0, std::ios::end);  <br/>size = inFile.tellg();  <br/>std::cout &lt;&lt; "Size of file: " &lt;&lt; size;  <br/>inFile.seekg(0, std::ios::beg);  <br/>oData = new  char[size + 1];  <br/>int counter = 0;  <br/>while (inFile >> std::noskipws >> ch) {  <br/>   oData[counter] = ch;  <br/> counter++;  <br/>}  <br/>return 0;
  </code></p>