Simple question, how does one create a function which takes an unsigned char std::vector
and spits out an unsigned char[]
with a length
. Thanks!
Ah, well it seems my problem was my knowledge of std::vector. I always believed that std::vector did not hold开发者_如何学编程 its values in linear fashion. That solves a lot of my problems. Thanks!
Just use: &v.front()
.
If you need a copy use std::copy
.
Unfortunately, it's not a one liner, but it's not too bad:
std::vector<unsigned char> v(10);
unsigned char* a = new unsigned char[v.size()];
std::copy(v.begin(), v.end(), a);
delete [] a;
精彩评论