I know that there\'re stdout/in/err for a program and I want to redirect a program\'s output to a file instead of the console output. And I now figure it out with the code b
You probably shouldn't set the stdout of your own process. The reason it's stdout is so that the caller (command line, whatever) can redirect it wherever it needs to, without your program having to know.
That's how things like "type foo.txt | more" work. If the type command felt free to redefine stdout to a file, that wouldn't work at all.
If you want to write to a stream, just open the stream and write to it.