Let me begin by saying I am beginner regarding C++. My problem is as follows: I want to create a 2-dim dynamic vector, with phone numbers on row 0, and row 1, 2, 3 and 4 with either 1 or 0 (1 - answered, 0 - not answered).
This will add 8 elements to the first row so you know have a grid of 5 rows where the first row has 9 columns and the rest of the rows have 1 column. Not much like a grid is it?
grid[1][6] = 2; This is out of bounds because the second row doesn't have 7 elements.
When you iterate the grid you use the number of columns on the first row for all the other rows but since they have fewer columns you are accessing elements out of bounds.
If you want the grid to be of a certain size you better specify that in the constructor and avoid using push_back. If you don't know the size when you create the grid or you want to resize it later you can use the resize member function in a similar way to the constructor.
Hmm.. That clarified a whole lot. But the thing is, I don't know how many numbers I'm gonna add. It's taken from a file that can vary in size. All I know is that the numbers of rows are const (5). If I cant use push_back in this case, what is it used for? :)