What is the easiest way to read binary (non-formated) data from std::cin
into either a string
or a stringstream
?
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: http://compgroups.net/comp.unix.programmer/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.