What is the simplest way to write to stdout in binary mode?

You can use setmode(fileno(stdout), O_BINARY)

Wrap it in an ifdef if you want to keep it compatible with Linux.

See also: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=vs-2017

Leave a Comment