Input and output to file:
DOS/Win: freopen("x.txt", "r", stdin);
freopen("x.txt", "w", stdout);
Input and output to the console:
The handle of the freopen function. The role of this handle is to restore the handle when you do not want to input or output to a file. You can reopen the standard console device file. The name of this device file is related to the operating system:
DOS/Win: freopen("CON", "r", stdin);
freopen("CON", "w", stdout);
In Linux, the console device is /dev/console: freopen("/dev/console", "r", stdin)