c++ - std::string or std::vector<char> to hold raw data -
i hope question appropriate stackoverflow... difference between storing raw data bytes (8 bits) in std::string
rather storing them in std::vector<char>
. i'm reading binary data file , storing raw bytes in std::string
. works well, there no problems or issues doing this. program works expected. however, other programmers prefer std::vector<char>
approach , suggest stop using std::string
it's unsafe raw bytes. i'm wondering why might unsafe use std::string
hold raw data bytes? know std::string
used store ascii text, byte byte, don't understand preference of std::vector<char>
.
thanks advice!
the problem not whether works or doesn't. problem is utterly confusing next guy reading code. std::string
meant displaying text. reading code expect that. you'll declare intent better std::vector<char>
.
it increases wtf/min in code reviews.
Comments
Post a Comment