title: C++ Exception "Access violation reading location"
body: <pre><code>#include &lt;iostream&gt;    
  #include &lt;fstream&gt;     
  using namespace std;
  
  struct review {
      string text;
      string date;
  };
  
  void getRegistry(int i) {
      review* reg = new review;
      ifstream file;
      file.open(&quot;test.txt&quot;, ios::binary);
      if (file) {
          file.seekg(i * sizeof(review), ios::beg);
          file.read(reinterpret_cast&lt;char*&gt;(reg), sizeof(review));
          cout &lt;&lt; reg-&gt;text;
          file.close();
      }
      delete reg;
  }
  
  void generateBinary()
  {
      ofstream arq(&quot;test.txt&quot;, ios::binary);
      review x;
      x.text = &quot;asdasdasd&quot;;
      x.date = &quot;qweqweqwe&quot;;
      for (int i = 1; i &lt;= 1000000; i++)
      {
          arq.write(reinterpret_cast&lt;const char*&gt;(&amp;x), sizeof(review));
      }
  
      arq.close();
  }
  
  
  int main() {
  
      generateBinary();
      getRegistry(2);
      
      return 0;
  }
  </code></pre>
  <p>Hello, I'm trying to make a program which writes several &quot;reviews&quot; to a binary file, then reads a certain registry. The program seems to work, but, in the end, it always throws an exception: &quot;Exception thrown at 0x00007FF628E58C95 in trabalho.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.&quot; How can I solve this? Thank you!</p>