Read binary data from std::cin

std::cin is not opened with ios_binary. If you must use cin, then you need to reopen it, which isn’t part of the standard.

Some ideas here: https://comp.unix.programmer.narkive.com/jeVj1j3I/how-can-i-reopen-std-cin-and-std-cout-in-binary-mode

Once it’s binary, you can use cin.read() to read bytes. If you know that in your system, there is no difference between text and binary (and you don’t need to be portable), then you can just use read without worrying.

Leave a Comment