Yeah you might need to find an old book. Standard streams are a unix thing from a looooong time ago. If anything, in MSDOS, it's an afterthought. I don't know at what point support was added to MSDOS, but there stands a good chance that it is later DOS. Someone else may know.
Only the last code example is DOS specific. Change the include from #include <cstdlib.h> to #include <stdlib.h>, and the command syntax from 'dir' to 'ls' and it will work in nix. There are many examples of this for unix, and there are subtle behavioural differences, although most of the concept is the same. You would need to use fork() instead or CreateProcess(). I don't really use them in programs, only in scripts, but I learned from the unix way as opposed to the Windows way, and I don't remember the transition being too difficult to Windows redirection. Good luck.