I have the following code, but when I run it, the output is printed instead of being copied to the text file.
void checkText()
{
ifstream my_file("test.txt");
if (my_file.good()) {
cout << "File exist" ;
}
else {
ofstream outputFile;
outputFile.open("test.txt");
outputFile << system("head -n 1024 words.txt");
outputFile.close();
cout << "Done!\n";
}
}
How do I print the system command to my text file?