Additional knowledge:
The resize function of the vector is to redefine the size of the array.
Create 3*3 arrays below
Method 1:
# Include <iostream> # include <vector> using namespace STD; int main () {int I, j; vector <int> array (3 ); // note that there is a space after the vector <> for (I = 0; I <3; I ++) array [I]. resize (3); for (I = 0; I <3; I ++) for (j = 0; j <3; j ++) array [I] [J] = I * j; for (I = 0; I <3; I ++) {for (j = 0; j <3; j ++) cout <array [I] [J] <""; cout <Endl;} return 0 ;}
Method 2 (initialize upon definition ):
# Include <iostream> # include <vector> using namespace STD; int main () {int I, j; vector <int> array (3, vector <int> (3); // you do not need to re-define the size after this definition. If you change the array size, change for (I = 0; I <3; I ++) for (j = 0; j <3; j ++) array [I] [J] = I * j; for (I = 0; I <3; I ++) {for (j = 0; j <3; j ++) cout <array [I] [J] <""; cout <Endl;} return 0 ;}
In fact, the outer layer size does not need to be defined, and the undefined extension with push_back is the most powerful place for vector to create a two-dimensional array.