So I am trying to copy a word by word from file1 to file2 , but my code fails in opening file2 (the output file)
void myFile::printWords(string inFile, string outFile)
{
ifstream file;
ofstream file2;
file.open(inFile);
file2.open(outFile);
if (!file.is_open() && !file2.is_open()){
string word;
while (!file.eof()){
file >> word;
file2 << word << '\n';
}
}
else{
cout << "error" << endl;
}
file.close();
file2.close();
}
Any idea why?