虽然string应该用于处理字符串,但我想知道在处理数据块时你应该在C++中使用什么结构.
我问这个是因为使用一个参数而不是传递char* data和size_t size(或自定义结构)会更好.
Fre*_*Foo 12
std::vector<unsigned char>
Run Code Online (Sandbox Code Playgroud)
或者,最好是,
std::vector<std::uint8_t>
Run Code Online (Sandbox Code Playgroud)
(在C++ 11中,uint8_t可以找到<cinttypes>.较旧的编译器,但不是MSVC,可能有C99标题<inttypes.h>.如果您的数据是16位单元的序列,请使用uint16_t等)
如果在编译时知道数据块的大小,std::array则是合适的; 它浪费的空间比vector.