开发者

How to access to memory block which allocated by std::vector?

Many people recommend vector class for variable length array. And I have to pass pointer to memory block to G开发者_开发知识库L. How can I access pointer to memory block allocated by std::vector?


Use the address of first element. If your vector is v then &v[0] will work.


ContainerType* pData  = &vec.front();


std::vector<int> v(1000);

int *p = &v[0];

//treat p as if it points to an array of 1000 ints
//all 1000 ints default-initialized with 0!
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜