For binary data in my opinion the best option is std::vector<unsigned char>
.
Using std::string
while technically works sends to the user the wrong message that the data being handled is text.
On the other side being able to accept any byte in a string is important because sometimes you know the content is text, but in an unknown encoding. Forcing std::string
to contain only valid and decoded text would be a big limitation for real world use.
This kind of limitation is one of the few things I don't like about QString
: this limitation makes it impossible for example to use a file selection dialog to open a file if the filename has a "wrong" (unexpected) encoding or if the encoding is actually invalid (it contains mistakes).