Monday, December 27, 2010

Pushing an array into a vector.

Programmer Question

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 push the elements one by on on to the first vector and then push that into the another vector which makes it 2d vector but I was wondering if there is any way in C++ to do this in a single loop. For example I want to do something like this:



myvector.pushback(A[1]+3); // where 3 is the size or number of columns in the array.


I understand this is not a correct code but I put this just for understanding purpose. Thanks



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails