Redirecting std input or output to any device or file is generally provided by all operating systems. The redirection is done generally using ">" for output to and "<" for input from a device. e.g.
$ gcc ./a.out > file
redirects the output to "file". The same can be done for input.
But the redirection is not supposed to be done by OS only. Languages like C also provide some library functions to support this functionality. Consider an example for function freopen(), used for the same purpose.
freopen("file.txt","w",stdout);
....
....
Now all the standard output will be streamed to file.txt.
$ gcc ./a.out > file
redirects the output to "file". The same can be done for input.
But the redirection is not supposed to be done by OS only. Languages like C also provide some library functions to support this functionality. Consider an example for function freopen(), used for the same purpose.
freopen("file.txt","w",stdout);
....
....
Now all the standard output will be streamed to file.txt.
