This is a home work question, so if you are not a fan of those I understand. Here is my code:
#include <fstream>
#include <iostream>
#include <string>
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() && 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 << line << endl; //input the line with add in it till the end of that line.
}
}
cout << "\nPress Enter..."; // press enter and then everything closes out.
cin.ignore();
outputFile.close();
myfile2.close();
myfile1.close();
return 0;
}
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?