You should use unformatted input with binary data, i.e.
"byte = stream.get();" instead of "stream >> byte;".