Can i push an array of int to a C++ vector?

后端 未结 8 1426
臣服心动
臣服心动 2020-12-15 21:03

Is there any problem with my code ?

std::vector weights;
int weight[2] = {1,2};
weights.push_back(weight);

It can\'t be compi

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 21:19

    Array can be added to container like this too.

        int arr[] = {16,2,77,29};
        std::vector myvec (arr, arr + sizeof(arr) / sizeof(int) );
    

    Hope this helps someone.

提交回复
热议问题