开发者

Unsigned char std::vector to unsigned char[]?

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜