vector <unsigned char> vs string for binary data

binary-data, c++, stl, string, vector

Solution

You should prefer `std::vector` over `std::string`. In common cases both solutions can be almost equivalent, but `std::string`s are designed specifically for strings and string manipulation and that is not your intended use.

Problem

Which is a better c++ container for holding and accessing binary data? ``` std::vector<unsigned char> ``` or ``` std::string ``` Is one more efficient than the other? Is one a more 'correct' usage?

Original source

Related problems