How to assign 2D vectors

Dec 14, 2009 at 9:11pm
1
2
double arr[][] = {{1,2},{3,4},{5,6}}
std::vector< std::vector<double> > my_vector;


How can I use the vector "assign()" function to copy the values of array arr to my_vector?
Dec 14, 2009 at 9:19pm
You can't.

You'll have to loop and assign elements one at a time. Or do std::copy in a loop or something.

Also, obligatory link:

http://cplusplus.com/forum/articles/17108/
Dec 14, 2009 at 9:28pm
Oh no.. but we could do it for 1D arrays :(
1
2
int myints[] = {1776,7,4};
third.assign (myints,myints+3);   // assigning from array. 
Dec 14, 2009 at 11:55pm
Right... but 1D arrays are simpler.
Topic archived. No new replies allowed.