Jun 26, 2015 at 2:02am
Question:
I get an error informing me my vector subscript is out of range, with the following code
1 2 3 4 5 6 7 8 9 10 11
|
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 4; j++)
{
std::cout << Numbers[i][j] << std::endl;
}
}
|
but i used the following the following and it runs fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
const int row = Numbers.size();
const int col = Numbers[0].size();
for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
{
std::cout << Numbers[i][j] << std::endl;
}
}
|
The value assigned at row is one. Shouldn't it be 3?
Why is Numbers[0].size() 12?
Is this all based on how a multidimensional vector is structured internally?
I keeping getting an error with
vector<vector<int>> v = {{1,2,3}, {4,5,6}, {7,8,9}};
Is this not allowed in C++
Last edited on Jun 26, 2015 at 2:05am