title: Unhandled exception at 0x50E2DF58 (msvcp120d.dll)
body: <p>I'm trying to read from a binary file into structs. The error is thrown when the program exits. I breakpointed it and the error comes up after return 0 is executed.</p>
  
  <p>When I run the program it actually displays the results. It does not crash until after the <code>system("pause")</code></p>
  
  <p>This is the actual error: Unhandled exception at 0x50E2DF58 (msvcp120d.dll) in struct reader.exe: 0xC0000005: Access violation reading location 0x007AB1EC.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  struct user{
      string name;
  };
  
  int main(){
      fstream file("file.dat", ios::in | ios::binary);
      user users[5];
  
      for (size_t i = 0; !file.eof(); i++)
      {
          file.read(reinterpret_cast&lt;char *&gt;(&amp;users[i]), sizeof(user));
      }
  
      file.close();
      size_t size = (sizeof(users) / sizeof(user));
  
      for (size_t i = 0; i &lt; size; i++)
      {
          cout &lt;&lt; users[i].name &lt;&lt; endl;
      }
  
      system("pause");
      return 0;
  }
  </code></pre>