title: ofstream file does not write
body: <p>I tried to write my own method to save a <code>Eigen::MatrixXd</code> object in a textfile. However, the file is empty after running this method. While debugging, I saw that the file does not open as I want. Can anyone tell me why?</p>
  <pre><code>#include&lt;Eigen\Dense&gt;
  #include&lt;iostream&gt;
  #include&lt;fstream&gt;
  #include&lt;string&gt;
  
  using namespace std;
  
  void savematrix(Eigen::MatrixXd matrix, string filename) {
      int m = matrix.rows();
      int n = matrix.cols();
      ofstream file(filename, ofstream::trunc);
      for (int i = 0; i &lt; m, i++;) {
          for (int j = 0; j &lt; n, j++;) {
              file &lt;&lt; m &lt;&lt; &quot;;&quot; &lt;&lt; n &lt;&lt; &quot;;&quot; &lt;&lt; matrix(i, j) &lt;&lt; endl;
          }
      }
      file.close();
  }
  
  int main() {
      Eigen::MatrixXd A(2, 2);
      A(0, 0) = 0;
      A(1, 0) = 1;
      A(0, 1) = 1;
      A(1, 1) = 0;
      cout &lt;&lt; A &lt;&lt; endl;
      savematrix(A, &quot;savematrixtest.txt&quot;);
  }
  
  </code></pre>