title: A simple c++ binary file working but why I cannot exit the program with enter?
body: <p>I found this example from here: <a href="https://www.tutorialspoint.com/reading-and-writing-binary-file-in-c-cplusplus" rel="nofollow noreferrer">https://www.tutorialspoint.com/reading-and-writing-binary-file-in-c-cplusplus</a></p>
  <p>I copy that and put into my Visual Studio 2019. The result is fine but I cannot exit the program with Enter. I have to press ESC wait for it before the program exit itself with &quot;exited with code -1073741819&quot;</p>
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  #include&lt;string&gt;
  using namespace std;
  struct Student {
      int roll_no;
      string name;
  };
  int main() {
      ofstream wf(&quot;student.dat&quot;, ios::out | ios::binary);
      if (!wf) {
          cout &lt;&lt; &quot;Cannot open file!&quot; &lt;&lt; endl;
          return 1;
      }
      Student wstu[3];
      wstu[0].roll_no = 1;
      wstu[0].name = &quot;Ram&quot;;
      wstu[1].roll_no = 2;
      wstu[1].name = &quot;Shyam&quot;;
      wstu[2].roll_no = 3;
      wstu[2].name = &quot;Madhu&quot;;
      for (int i = 0; i &lt; 3; i++)
          wf.write((char*)&amp;wstu[i], sizeof(Student));
      wf.close();
      if (!wf.good()) {
          cout &lt;&lt; &quot;Error occurred at writing time!&quot; &lt;&lt; endl;
          return 1;
      }
      ifstream rf(&quot;student.dat&quot;, ios::out | ios::binary);
      if (!rf) {
          cout &lt;&lt; &quot;Cannot open file!&quot; &lt;&lt; endl;
          return 1;
      }
      Student rstu[3];
      for (int i = 0; i &lt; 3; i++)
          rf.read((char*)&amp;rstu[i], sizeof(Student));
      rf.close();
      if (!rf.good()) {
          cout &lt;&lt; &quot;Error occurred at reading time!&quot; &lt;&lt; endl;
          return 1;
      }
      cout &lt;&lt; &quot;Student's Details:&quot; &lt;&lt; endl;
      for (int i = 0; i &lt; 3; i++) {
          cout &lt;&lt; &quot;Roll No: &quot; &lt;&lt; wstu[i].roll_no &lt;&lt; endl;
          cout &lt;&lt; &quot;Name: &quot; &lt;&lt; wstu[i].name &lt;&lt; endl;
          cout &lt;&lt; endl;
      }
      return 0;
  }
  </code></pre>