开发者

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

开发者 https://www.devze.com 2023-01-06 15:16 出处:网络
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!

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

精彩评论

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