Reputation: 197
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?
Upvotes: 1
Views: 1464
Reputation:
you can also use for printing the output in a text file freopen(); command
freopen("input file name.txt", "r", stdin);
freopen("output file name.txt", "w", stdout);
Upvotes: 0