Is there way to set stdout to binary mode?

前端 未结 2 1531
庸人自扰
庸人自扰 2020-12-30 08:02

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

2条回答
  •  抹茶落季
    2020-12-30 08:35

    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.

提交回复
热议问题