title: binary read/write arbitrary std::vector<std::vector<int> > in c++
body: <p><em>Hi</em>,
  I would like to store binary a <code>std::vector&lt;std::vector&lt;int&gt; &gt;</code> object MATRIX in a file. </p>
  
  <pre><code>out.write((char*)&amp;MATRIX, sizeof(MATRIX));
  </code></pre>
  
  <p>The problem is, that only the column dimension is fixed. The row dimension changes.
  If I read the object out of the binary file, it's not enough to know only the size, isn't it? So, initializing e.g. a second matrix with</p>
  
  <pre><code>std::vector&lt;std::vector&lt;int&gt; &gt; MATRIX2;
  for ( int i=0;i&lt;column_dim;i++ ) MATRIX2.push_back ( vector&lt;int&gt; ( 0 ) );
  ifstream in(cstr, ios::in | ios::binary);
  </code></pre>
  
  <p>and reading the object data with</p>
  
  <pre><code>ifstream in(cstr, ios::in | ios::binary);    
  in.read((char*)&amp; MATRIX2, fSize);
  </code></pre>
  
  <p>makes no sense, because the compiler has no clue about the structure of the saved data. 
  My question:
  Is there any better way of solving this problem than saving the matrix structure (all info about the row dimensions) in a second file, reading it and creating a MATRIX2 with the appropriate structure which is then filled by using </p>
  
  <pre><code>ifstream in(cstr, ios::in | ios::binary);    
  in.read((char*)&amp;nn_H_test, fSize);
  </code></pre>
  
  <p>?</p>