在std :: vector中表示原始字节的最佳方法?

jap*_*iss 2 c++ sockets buffer stl stdvector

我正在使用ZeroMQ库void *来表示任意二进制数据块.但是我想std::vector用来复制和移动这些块.std::vector表示原始字节的首选,惯用方法是什么?我目前正在使用,std::vector<unsigned char>但我想确保我的代码对其他人有意义.

joh*_*ohn 8

std::vector<unsigned char>
Run Code Online (Sandbox Code Playgroud)

要么

#include <cstdint>

std::vector<std::uint8_t>
Run Code Online (Sandbox Code Playgroud)

对我来说似乎都很好.

  • `uint8_t`将不存在于没有8位字节的系统上.`uint_least8_t`可能是更好的选择,但`unsigned char`是最好的选择. (2认同)