What is the simplest way to convert array to vector?

后端 未结 5 1415
醉话见心
醉话见心 2020-11-27 11:24

What is the simplest way to convert array to vector?

void test(vector _array)
{
  ...
}

int x[3]={1, 2, 3};
test(x); // Syntax error.
         


        
5条回答
  •  我在风中等你
    2020-11-27 11:50

    One simple way can be the use of assign() function that is pre-defined in vector class.

    e.g.

    array[5]={1,2,3,4,5};
    
    vector v;
    v.assign(array, array+5); // 5 is size of array.
    

提交回复
热议问题