Today we want to use vector to realize the function of two-dimensional array, and try to put the two-dimensional vector. Who knows when he got started, he met Ray.
The form of the code is roughly as follows:
VECTOR<VECTOR<INT>>VV (3);
Vv.clear ();
for (int i = 0; i < 3; i++)
vv[i].push_back (0);
The vacuuming operation was performed because the two-dimensional vector was reused. However, there is a problem: vector subscript out of range
Later found in Single-step debugging, Clear () makes the size of the two-dimensional array 0, and the previously declared structure of the 3 one-dimensional array is corrupted.
When executing to the for header, the automatic window is as follows:
Make a change to the above code:
VECTOR<VECTOR<INT>>VV (3);
Vv.clear ();
Vv.resize (3);
for (int i = 0; i < 3; i++)
vv[i].push_back (0);
The same is done to the for header when the automatic window is as follows: