| Catfish3 (274) | |
|
Is it bad practice to use std::string instead of std::vector<char>, for reading non-text (binary) data from file streams? And if yes, why? | |
|
|
|
| JLBorges (1752) | |
std::char_traits<char> doesn't make any sense for binary (non- character) data.I would go for: std::vector< unsigned char > if the bytes are to be treated as unsigned, std::vector< signed char > if not.
| |
|
Last edited on
|
|
| Catfish3 (274) | ||
Are there any repercussions for this, in the form of the data not being read/stored/written correctly? Thank you. | ||
|
|
||
| cire (2345) | |
|
http://c2.com/cgi/wiki?PrincipleOfLeastAstonishment If it's a string, I should be able to treat it like a string. Does cout << string_that_is_not_a_string make sense? Does it make sense to be able to use substr on a container of binary data?I just think it doesn't properly convey intent. | |
|
|
|
| L B (3805) | |
using StreamableRawData = std::basic_string<unit8_t>;Does this convey intent? | |
|
Last edited on
|
|
| Catfish3 (274) | |||
Relevant. Because compiler optimization does seem to break my program. | |||
|
|
|||