In general, what is the best way of storing binary data in C++? The options, as far as I can tell, pretty much boil down to using strings or vector
I use std::string
for this too, and have never had a problem with it.
One "pointer," which I just received a sharp reminder of in a piece of code yesterday: when creating a string from a block of binary data, use the std::string(startIter, endIter)
constructor form, not the std::string(ptr, offset, length)
form -- the latter makes the assumption that the pointer points to a C-style string, and ignores anything after the first zero character (it copies "up to" the specified length
, not length
characters).