I came across Reading the binary file into the vector of unsigned chars and tested the code discussed in the question.
The code of interest is below:
typedef unsigned char BYTE;
std::ifstream file(filename, std::ios::binary);
file.unsetf(std::ios::skipws);
std::vector<BYTE> vec;
vec.insert(vec.begin(),
std::istream_iterator<BYTE>(file),
std::istream_iterator<BYTE>());
According to Benjamin Lindley's answer at Why std::istream_iterator ignores newline characters?, istream::operator>>(char)
skips white spaces. But the type above is unsigned char
, and the file was opened with std::binary
.
Why did the code require an explicit call to file.unsetf(std::ios::skipws)
(or alternately, file >> std::noskipws)
?