vector< unsigned char> vs二进制数据的字符串

vector< unsigned char> vs二进制数据的字符串

问题描述:

哪个是更好的c ++容器,用于保存和访问二进制数据?

Which is a better c++ container for holding and accessing binary data?

std::vector<unsigned char>

std::string

比另一个更有效吗?
$

Is one more efficient than the other?
Is one a more 'correct' usage?

您应该优先使用 std :: vector $ c> std :: string 。在通常情况下,两个解决方案几乎是等价的,但 std :: string s专为字符串和字符串操作设计,这不是您的预期用途。

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