首页 > 代码库 > 动态创建二维数组

动态创建二维数组

vector创建二维数组初始化二维数组vector<vector <int> > ivec(n ,vector<int>(m));      //n*m的二维vectorvector<vector <int> > ivec(n , vector<int>(m, 0));  //n*m的二维vector,所有元素为0动态创建m*n的二维方法一:vector<vector <int> > ivec;ivec.resize(n);for(int i = 0; i < n; i++) ivec[i].resize(m);方法二:vector<vector <int> > ivec;ivec.resize(n, vector<int>(m));动态创建二维数组a[n][m]C语言版:#include<malloc.h>int **a = (int **)malloc(n *sizeof(int *));for(int i = 0; i < n; i++)    a[i] = (int *)malloc(m *sizeof(int));C++版:int **a = new int *[n];for(int i = 0; i < n; i++) a[i] = new int[m];

  

动态创建二维数组