title: Are there any special requires for the use of fstream?
body: <p>I want to use fstream to write and read an array,some bug happened...
  The code of write process is:</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;fstream&gt;
  
      using namespace std;
      int main()
      {
         float a[4][16] = {
                3.16216,
                5.97973,
               4.18243,
               4.60135,
               2.7027,
               6.96622,
               6.50676,
               4.28378,
               5.43919,
               8.51352,
               5.30405,
               8.10135,
               2.07432,
               7.83784,
               3.67568,
               8,
               5.25197,
               8.83465,
               6.35433,
              6.65354,
          5.01575,
          7.32283,
          6.95276,
          4.50394,
          4.77165,
          8.18898,
          5.43307,
          7.65354,
          4.64567,
          8.03937,
          4.48031,
          7.49606,
          4.13333,
          6.8381,
          4.94286,
          5.09524,
          3.19048,
          6.48571,
          9.17143,
          4.78095,
          4.24762,
          8.30476,
          8.22857,
          7.33333,
          3.27619,
          9.38095,
          2.56191,
          7.44762,
          4.05195,
          6.94805,
          5.12338,
          5.35065,
          3.43507,
          6.71429,
          8.48052,
          3.94805,
          5.88312,
          8.27922,
          7.34416,
          7.81818,
          2.79221,
          8.90909,
          4.25325,
          7.26623 };
  
      ofstream database("test.db");
      for (int i = 0; i &lt; 4; i++)
      {
          database.write((char *)a[i], sizeof(float) * 16);
      }
      database.close();
  }
  </code></pre>
  
  <p>The code of read process is:</p>
  
  <pre><code>    float a[4][16] = { 0 };
  ifstream database("test.db");
  for (int i = 0; i &lt; 4; i++)
  {
      database.read((char *)a[i], sizeof(float) * 16);
      for (int j = 0; j &lt; 16; j++)
      {
          cout &lt;&lt; "output: " &lt;&lt; a[i][j] &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>some bug happened:</p>
  
  <p><a href="https://i.stack.imgur.com/YUub6.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>The last two elements can not be loaded correctly. but, if i change the size of the array , for example ,change a[4][16] to a[4][15], everything will be ok. Can someone give me some advice, Thanks a lot!</p>