What is the simplest way to convert array to vector?

后端 未结 5 1401
醉话见心
醉话见心 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:54

    Pointers can be used like any other iterators:

    int x[3] = {1, 2, 3};
    std::vector v(x, x + 3);
    test(v)
    

提交回复
热议问题