cast vector<unsigned char> to uint8_t*

c++, casting, stdvector

Solution

in most of the case, `unsigned char` is same as `uint8_t`. if c++11 available, you can use this to conform it

static_assert(std::is_same<unsigned char, uint8_t>::value, "uint8_t is not unsigned char");

then you can just use `data` to get what you want

vector<unsigned char> vec = // your vector
uint8_t *data = vec.data();

Problem

I have a function that requires `uint8_t*` as an input (unsigned char). However, I have my string saved as `vector<unsigned char>`. How to convert that to `uint8_t*` for my function to be able to accept? Thank you.

Original source