title: How to write dynamically allocated 2D 'array' in a file?
body: <p>So for a school assignment I was writing a program that uses dynamic 2D 'arrays' to model matrices and perform operations on them. So what I did was create a  structure called <em>matrix</em> which contains two integers for the rows and columns, and a double pointer for the 'array'. I initialized the pointers like this:</p>
  
  <pre><code>int **ary=new int*[row];
  for(int i=0;i&lt;row;++i)
       ary[i]=new int[col];
  </code></pre>
  
  <p>Now I know that my program is going to look horribly slow and inefficient and generally horrible to people on this site, but just keep in mind that I am doing a <em>school assignment</em> and I can't use <em>fancy</em> things like vectors and all. </p>
  
  <p>Then I tried to write and then read the structure objects in a binary file like using an fstream object <em>y</em> like this:</p>
  
  <pre><code>matrix M;
  y.write((char*)&amp;M,sizeof M);
  y.read((char*)&amp;M,sizeof M);
  </code></pre>
  
  <p>The program worked, but what I entered was different from what the file read. Why is that so? And what are other methods (that use fstream) to store my matrices in a file?</p>
  
  <p><strong>NOTE:</strong> As is evident, I am completely new to this site, and as of yet I do not know the proper, um, etiquette of asking questions on this site. If my question seems weird in some way or is missing some information, please leave a comment. Constructive edits are welcome.</p>