Is there way to set stdout to binary mode? In which mode is stdout without any operations, from my debugging issues I assume that it is in text mode, is it true?
I t
The simple answer is no. The mode is determined when the iostream object is constructed, and cannot be changed later. Some implementations may provide a means of doing it later, but this isn't standardized. On some implementations, doing an freopen
on stdout
might change the mode, although I think that formally, this is forbidden in C++. (It is implementation defined in C.) And apparently, it doesn't work on your implementation.
You're best bet is to find out how your system names the console device ("/dev/tty"
under Unix; "CONS"
, I think, under Windows), open it in the desired mode, and output to it.
I tried code presented below to set stdin and stdout to binary mode (on Windows):
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
...
#ifdef _WIN32
setmode(fileno(stdout),O_BINARY);
setmode(fileno(stdin),O_BINARY);
#endif
Under Linux you can't do it, because on this platform binary and text mode is the same thing.