Is it possible to show cout output on a file instead of showing it in the console/terminal?
#include <iostream>
#include <fstream>
void showhello()
{
cout << "Hello World" << endl;
}
int main(int argc, const char** argv)
{
ofstream fw;
fw.open("text.txt");
fw << showhello() << endl;
}
If I simply put the cout << "Hello World" << endl; in the main, it will of course show "Hello World" in the terminal. Now instead of showing it in the terminal, I want to make it show in the text.txt file.
Restriction: Let's say the function showhello() contains a thousand of cout output, so you cannot use something like:
fw << "Hello World" << endl;
or a copy paste in a string. It must be fw << function.