C++11: istream.get() stops on EOM

169 views Asked by At

I have a problem with c++(11) inputstreams, specifically filestreams. After I open a new stream with this:

ifstream stream;
stream.open("C:\somefile.txt");

And when I try to read from it and the read operation encounters and EOM-byte (0x19) the stream is set to badbit which is not what I want. I want to read until the definit end of the file. This is how I read

char buffer[8];
stream.read(buffer, 8);

and then I check like that:

if(stream.fail()) return -1;

How can I read from the stream without stopping at EOM-bytes (or equal)?

1

There are 1 answers

0
utnapistim On BEST ANSWER

Open the file as a binary stream instead:

ifstream stream{ "C:\\somefile.txt", std::ios::binary };

This should cause the stream to ignore the value of individual bytes, on reading (and simply read as a block).