Pushing an array into a vector

后端 未结 8 1447
一整个雨季
一整个雨季 2020-12-17 01:26

I\'ve a 2d array, say A[2][3]={{1,2,3},{4,5,6}}; and I want to push it into a 2D vector(vector of vectors). I know you can use two for loops to pus

8条回答
  •  情书的邮戳
    2020-12-17 02:26

    Hm... I can produce a partial answer but not a full one.

    int elementCount = 6; // I wonder if this can be done somehow with sizeof(A) * sizeof(A[0])
    int* end = A + elementCount;
    for(int* current = A; current < end; ++current) {
        myvector.pushback(*current);
    }
    

提交回复
热议问题