Now that c++17 has std::byte
, I was looking for a way to convert code that reads files to char
into code that reads files into byte
. A file contains bytes, not a bunch of integers.
Then I read this question and this other question where people argued that reading files into byte
is wrong, and that reading files into char
is right.
If byte
is not designed for the purpose of accessing memory, and by analogy, files, then what is the its purpose? As is quoted in the other two questions:
Like char and unsigned char, it can be used to access raw memory occupied by other objects (object representation), but unlike those types, it is not a character type and is not an arithmetic type. A byte is only a collection of bits, and only bitwise logic operators are defined for it.
This sounds like the exact type that should be used for reading files, not characters.
See Question&Answers more detail:os