title: How to read the text file and create Mat object in C++
body: <p>Hi i  have being able to write a Mat object in to a text file. As follows,</p>
  
  <pre><code>std::fstream outputFile;
      outputFile.open( "myFile.txt", std::ios::out ) ;
  
      outputFile &lt;&lt; des_object.rows &lt;&lt; std::endl;
      outputFile &lt;&lt; des_object.cols &lt;&lt; std::endl;
  
      for(int i=0; i&lt;des_object.rows; i++)
      {
          for(int j=0; j&lt;des_object.cols; j++)
          {
              outputFile &lt;&lt; des_object.at&lt;float&gt;(i,j) &lt;&lt; std::endl;
          }
  
      }
      outputFile.close( );
  </code></pre>
  
  <p>In my code in the first 2 lines im printing the row count and the column count to use when im reading it back.
  But im unable to read the text file and create the Mat Object again. </p>
  
  <p>The following is the code i tried. Not sure whether my code is correct.</p>
  
  <pre><code>Mat des_object1;
      std::ifstream file("myFile.txt");
      std::string str; 
      int rows;
      int cols;
      int a = 0;
      while (std::getline(file, str))
      {
          int i = 0;
          int j = 0;
  
          if(a == 0){
              rows = std::stoi( str );
          }else if(a == 1){
              cols = std::stoi( str );
          }else{
  
              for(i; i&lt; rows; i++)
              {
                  for(j; j&lt;cols; j++)
                  {
                       des_object1.at&lt;float&gt;(i,j) = ::atof(str.c_str());
                       break;
                  }
              }
  
          }
          ++a;
      }
  </code></pre>