C++: Cannot copy line from an input file to an output file : <p>This is a home work question, so if you are not a fan of those I understand. Here is my code:</p>

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

int main()
{
    fstream myfile1("datafile1.txt"); //this just has a bunch of names in it
    fstream myfile2("cmdfile1.txt");  //has commands like "add bobby bilbums"
    ofstream outputFile("outfile1.txt"); //I want to take the "add bobby" command and copy the name into this new file.
    string line;
    if (myfile1.is_open() &amp;&amp; myfile2.is_open()) //so I open both files
    {
        if (myfile2, line == "add"); //If myfile2 has an "add" in it
        {
            outputFile.is_open(); //open outputfile
            outputFile &lt;&lt; line &lt;&lt; endl; //input the line with add in it till the end of that line.
        }
    }
    cout &lt;&lt; "\nPress Enter..."; // press enter and then everything closes out.
    cin.ignore();
    outputFile.close();
    myfile2.close();
myfile1.close();
return 0;
}
</code></pre>

<p>Problem is, though the outputFile is always empty. It never copies any lines from cmdfile1 into the output file. Does anyone know what I am missing here? </p>
