Initializing a 2D vector using initialization list in C++11
How can i initialize a 2D vector using an initialization list? for a normal vector doing : vector<int> myvect {1,2,3,4}; would suffice. But for a 2D one doing : vector<vector<int>> myvect{ {10,20,30,40}, {50,60,70,80} }; What is a correct way of doing it? And how can i iterate through it using for? for(auto x: myvect) { cout<<x[j++]<<endl; } this for only shows: 10,1 ! And by the way what does this mean ? vector<int> myvect[5] {1,2,3,4}; i saw it here and cant understand it! Link What is a correct way of doing it? The way you showed is a possible way. You could also use: vector<vector<int>>