So I try this:
std::vector< std::vector<int> > matrix(4);
matrix[0][0] = 1;
matrix[0][1] = 2;
matrix[0][2] = 3;
matrix[0][3] = 1;
matrix[1][0] = 1;
matrix[1][1] = 2;
matrix[1][2] = 3;
matrix[1][3] = 1;
matrix[2][0] = 1;
matrix[2][1] = 2;
matrix[2][2] = 3;
matrix[2][3] = 1;
matrix[3][0] = 1;
matrix[3][1] = 2;
matrix[3][2] = 3;
matrix[3][3] = 1;
But something goes wrong and my app dies at runtime=( What to do? How to embed values into vector of vectors correctly?
Use this:
std::vector< std::vector<int> > matrix(4, std::vector<int>(4));
This initializes your outer vector with 4 copies of std::vector<int>(4)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With