how to read two txt files in c++
<p>I want to read two matrices from two different txt files, and say output them in another one.
I doesn't write all of them, it only writes the fist one and "Hi" and stops there.
So I believe it cannot read the second file.
Here is the code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;

#define I 5
#define J 5
#define P 2
int i,j,k;  //for loops

int main ()
{
    ifstream inFile;
    ofstream outFile;

    double C[I][J];
    double u[I][J];
    double UB = 0;

    outFile.open("results.txt");
    // READ U0
    inFile.open("u.txt", ios::in);
    if (! inFile) {
        cerr &lt;&lt; "unable to open file u.txt for reading" &lt;&lt; endl;
        return 1;
    }
    for(i = 0; i &lt; I; i++)
        for(j = 0; j &lt; J; j++)
            inFile &gt;&gt; u[i][j];

    outFile &lt;&lt; "u" &lt;&lt; endl;
    for(i = 0; i &lt; I; i++)
    {
        for(j = 0; j &lt; J; j++)
            outFile &lt;&lt; u[i][j];
            outFile &lt;&lt; endl;
    }
    outFile &lt;&lt; "Hi";

    //READ C
    inFile.open("C.txt", ios::in);
    if (! inFile) {
        cerr &lt;&lt; "unable to open file C.txt for reading" &lt;&lt; endl;
        return 1;
    }
    for(i = 0; i &lt; I; i++)
        for(j = 0; j &lt; J; j++)
            inFile &gt;&gt; C[i][j];
    outFile &lt;&lt; "C" &lt;&lt; endl;

    outFile &lt;&lt; "UB=" &lt;&lt; UB;


    inFile.close();
    outFile.close();

    return 0;

}
</code></pre>
