user6697
user6697

Reputation: 135

cast vector<unsigned char> to uint8_t*

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.

Upvotes: 3

Views: 10451

Answers (1)

Bryan Chen
Bryan Chen

Reputation: 46578

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();

Upvotes: 10

Related Questions