Why does a two-dimensional array of int initialize contiguously? Meanwhile the two dimensional vector is initialize per set of numbers.
int main()
{
array<array<int, 2>, 2> td{ 2, 6, 4, 8 }; //array of arrays
for (int i = 0; i < 2; ++i)
for(int j = 0; j < 2; ++j)
cout << td[i][j] << ' ';
cout << endl;
vector<vector<int>> vtd{ { 5, 1 }, { 0, 2 } }; //vector of vectors
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
cout << vtd[i][j] << ' ';
return 0;
}
Here are the results:
2 6 4 8
5 1 0 2
std::arrayinitialization, as it's really missing braces.{ {0,1}, {2,3} }from the VS2013 MSVC compiler. Then I used{0,1,2,3}and it works.