title: diff: output.txt: No such file or directory
body: <p>im trying to run this code on my linux server using terminal, but i keep getting this error.</p>
  
  <ul>
  <li>diff: output1.txt: No such file or directory </li>
  <li>diff: output3.txt: No such file or directory</li>
  </ul>
  
  <p>what im trying to do is multiply two matrices by taking inputs from any .txt file given that contains matrices inside and output the answer to another .txt file. Also checking that multiplication might contain an error like multiply 2*2 by 3*2 and give the error on another .txt file. </p>
  
  <p>it is like checking cases.</p>
  
  <p>here is my code.  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cstring&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  //function to check if a number (in string format) is double or not
  bool is_double(const string&amp; s)
  {
     istringstream in(s);
      double d;
      return in &gt;&gt; d &gt;&gt; ws &amp;&amp; in.eof();  
  }
  
  //main function
  int main(int argc, char* argv[]){
     //check if all required command line arguments are passed
     if (argc &lt; 4)
     {
         cerr&lt;&lt;"error"&lt;&lt;endl;
         return -1;
     }
  
  string inputfile1(argv[1]); //input file containing first matrix
     string inputfile2(argv[2]); //input file containing second matrix
     string outputfile(argv[3]); //output file containing matrix obtained after multiplication
     //extract names of files
     inputfile1=inputfile1.substr(inputfile1.find("=")+1);
     inputfile2=inputfile2.substr(inputfile2.find("=")+1);
     outputfile=outputfile.substr(outputfile.find("=")+1);  
     /*cout&lt;&lt;"input file1:"&lt;&lt;inputfile1&lt;&lt;endl;
     cout&lt;&lt;"input file2:"&lt;&lt;inputfile2&lt;&lt;endl;
     cout&lt;&lt;"output file:"&lt;&lt;outputfile&lt;&lt;endl;*/
  
     //file stream for files
     ifstream infile1(inputfile1.c_str(),ifstream::in);
     ifstream infile2(inputfile2.c_str(),ifstream::in);
     ofstream outfile(outputfile.c_str(), ofstream::out);
     if(!infile1 || !infile2 || !outfile)
     {
         cerr&lt;&lt;"error"&lt;&lt;endl;
         return -1;
     }
     double** inmatrix1; //input matrix 1
     double** inmatrix2; //input matrix 2
     double** outmatrix; //output matrix
     int m=0,n=0; //dimensions of input matrix 1
     int p=0,q=0; //dimensions of input matrix 2
  
     //extract dimensions from input file 1
     string line="";
     while(getline(infile1,line)!=NULL)
     {
         //count columns
         int len = line.size();
         int cols = 0;
         for(int i=0;i&lt;len;i++)
         {
             if(!isspace(line[i]))
                 cols++;
         }
         n=cols;
         m++;
     }  
     //cout&lt;&lt;"matrix1 dimensions:"&lt;&lt;m&lt;&lt;" "&lt;&lt;n&lt;&lt;endl;
  
     //extract dimensions from input file 2
     line="";
     while(getline(infile2,line)!=NULL)
     {
         //count columns
         int len = line.size();
         int cols = 0;
         for(int i=0;i&lt;len;i++)
         {
             if(!isspace(line[i]))
                 cols++;
         }
         q=cols;
         p++;
     }  
     //cout&lt;&lt;"matrix2 dimensions:"&lt;&lt;p&lt;&lt;" "&lt;&lt;q&lt;&lt;endl;
  
     //check if multilplication possible
     if(n!=p)
     {
         cerr&lt;&lt;"error"&lt;&lt;endl;
         return -1;
     }
  
     //allocate space for matrices
     inmatrix1 = new double*[m];
     for(int i = 0;i&lt;m;++i)
     {
         inmatrix1[i]=new double[n];      
     }
     inmatrix2 = new double*[p];
     for(int i = 0;i&lt;p;++i)
     {
         inmatrix2[i]=new double[q];      
     }
     outmatrix = new double*[m];
     for(int i = 0;i&lt;m;++i)
     {
         outmatrix[i]=new double[q];      
     }
     //read data from files into matrices
     cout&lt;&lt;"Reading matrix 1..."&lt;&lt;endl;
     //matrix 1
     infile1.clear();
     infile1.seekg(0,ios::beg);
     line="";
     int j=0,k=0;
     while(getline(infile1,line))
     {
         stringstream ss(line);
         string token;
         k=0;
         while(getline(ss,token,' '))
         {
             //check if double or not
             if(!is_double(token))
             {
                 cerr&lt;&lt;"error"&lt;&lt;endl;
                 return -1;
             }
             else
             {
                 inmatrix1[j][k]=atof(token.c_str());
                 k++;  
             }          
         }
         j++;  
     }
     cout&lt;&lt;"Matrix 1 read!"&lt;&lt;endl;
  
     //matrix 2
     cout&lt;&lt;"Reading matrix 2..."&lt;&lt;endl;
     infile2.clear();
     infile2.seekg(0,ios::beg);
     line="";
     j=0,k=0;
     while(getline(infile2,line))
     {
         stringstream ss(line);
         string token;
         k=0;
         while(getline(ss,token,' '))
         {
             //check if double or not
             if(!is_double(token))
             {
                 cerr&lt;&lt;"error"&lt;&lt;endl;
                 return -1;
             }
             else
             {
                 inmatrix2[j][k]=atof(token.c_str());
                 k++;  
             }          
         }
         j++;  
     }
     cout&lt;&lt;"Matrix 2 read!"&lt;&lt;endl;
  
     //print both matrices
     cout&lt;&lt;"Matrix 1:"&lt;&lt;endl;
     for(int i=0;i&lt;m;i++)
     {
         for(int j=0;j&lt;n;j++)
         {
             cout&lt;&lt;inmatrix1[i][j]&lt;&lt;" ";
         }
         cout&lt;&lt;endl;
     }
     cout&lt;&lt;"Matrix 2:"&lt;&lt;endl;
     for(int i=0;i&lt;p;i++)
     {
         for(int j=0;j&lt;q;j++)
         {
             cout&lt;&lt;inmatrix2[i][j]&lt;&lt;" ";
         }
         cout&lt;&lt;endl;
     }  
  
     //multiply two matrices
     for(int i = 0; i &lt; m; ++i)
     {
         for(int j = 0; j &lt; q; ++j)
              for(int k = 0; k &lt; n; ++k)
              {
                  outmatrix[i][j] += inmatrix1[i][k] * inmatrix2[k][j];
              }
     }
  
     //print result to file  
     for(int i=0;i&lt;m;i++)
     {
         for(int j=0;j&lt;q;j++)
         {
             outfile&lt;&lt;outmatrix[i][j]&lt;&lt;" ";
         }          
         outfile&lt;&lt;endl;
     }  
  
     //close files
     infile1.close();
     infile2.close();
     outfile.close();
     return 0;
  }
  </code></pre>