Convert std::vector to array

后端 未结 1 1319
太阳男子
太阳男子 2020-12-14 17:55

I have a library which expects a array and fills it. I would like to use a std::vector instead of using an array. So instead of

int array[256];
object->ge         


        
1条回答
  •  Happy的楠姐
    2020-12-14 18:36

    Yes:

    std::vector array(256); // resize the buffer to 256 ints
    object->getArray(&array[0]); // pass address of that buffer
    

    Elements in a vector are guaranteed to be contiguous, like an array.

    0 讨论(0)
提交回复
热议问题