简体   繁体   中英

Best way to represent raw bytes in a std::vector?

I'm working with the ZeroMQ library which uses void * to represent blocks of arbitrary binary data. However I'd like to use std::vector to copy and move these blocks around. What is the preferred, idiomatic way to make a std::vector representing raw bytes? I'm currently using a std::vector<unsigned char> but I want to make sure my code makes sense to other people.

Either

std::vector<unsigned char>

or

#include <cstdint>

std::vector<std::uint8_t>

both seem fine to me.

If you don't know the nature of your data, unsigned char is the smallest chunk of bits that you can represent without getting messy. Therefore it is a common type for any kind of arbitrary memory block.

So your vector looks perfectly fine the way it is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM