title: I want to add two matrices of String type. The user will not enter the number of rows or columns. The user will enter the array only
body: <p>How do I add two matrices of String type? The user will not enter the number of rows or columns. The user will enter the array only. For example, for the input <code>[5 4-1; 2 1 4] + [3 -5 2.5; 1 2 3]</code>, the output should be <code>[8 -1 1.5; 3 3 7]</code> 
  whats the error in stof function and the add?
  this is my code:</p>
  
  <pre><code>//define a stm fucntion to convert string to matrix
  vector &lt;vector &lt;float&gt; &gt; stm(string mat1)
  {
      //now let us build the matrix1 by iterating over the string mat1
      //we will break the string over the point where we ";"
      vector &lt;vector &lt;float&gt; &gt; matrix1;
      int index1 = 0;
      for (float i = 0; i &lt; mat1.length(); i++)
      {
          string temp = " ";
          while (mat1[i] != ';')
          {
              temp += mat1[i];
              //now the temp string contains the elements of first row
              //now we will break this at point where we get " " (spaces)
              for (float j = 0; j &lt; temp.length(); j++)
              {
                  string num1;
                  int index2 = 0;
                  while (temp[j] != ' ')
                  {
                      num1 += temp[j];
                      //ntf is number to be filled at that position
                      j++;
                  }
                  float ntf = stof(num1);
                  matrix1[index1][index2] = ntf;
                  index2++;
              }
              i++;
          }
          index1++;
      }
      return matrix1;
  }
  
  int main()
  {
      string mat1; cin &gt;&gt; mat1;
      string mat2; cin &gt;&gt; mat2;
      vector &lt;vector &lt;float&gt; &gt; matrix1, matrix2;
      matrix1 = stm(mat1);
      matrix2 = stm(mat2);
      //now let us write a code to add the two matrices;
      vector &lt;float&gt; add;
      for (float i = 0; i &lt; matrix1.size(); i++)
      {
          for (float j = 0; j &lt; matrix1[0].size(); j++)
          {
              add[i][j] = matrix1[i][j] + matrix2[i][j];
          }
      }
      for (float i = 0; i &lt; add.size(); i++)
      {
          for (float j = 0; j &lt; add[0].size(); j++)
          {
              cout &lt;&lt; add[i][j] &lt;&lt; " ";
          }
          cout &lt;&lt; endl;
      }
      return 0;
  
  </code></pre>
  
  <p>this is an example 
  input</p>
  
  <blockquote>
  <pre><code> [5 4 -1;3 2 1]+[1 2 3;5 4 8]
  </code></pre>
  </blockquote>
  
  <p>output </p>
  
  <blockquote>
  <pre><code>[6 6 2;8 6 9]
  </code></pre>
  </blockquote>