Remove unused headers, use strlen instead of !string::empty().
Switch stdout to binary mode in Windows.

Unfortunately, there is no working portable method of doing this.
In C99 freopen can have NULL filename and only change the mode, but that
is not implemented on Windows (according to the documentation freopen
crashes if any argument is NULL).