## 一：C++ new 法

`#include#includeusing namespace std;void main(){    int row, col;    int **element = NULL;    cin>>row        >>col;    //动态开辟数组    element = new int *[row];    for (int i = 0; i < row; i++)    {        element[i] = new int[col];    }    //输入数组    cout<<endl;    for (i = 0; i < row; i++)    {        for (int j = 0; j < col; j++)        {            cin>>element[i][j];        }    }    //输出数组    cout<<endl;    for (i = 0; i < row; i++)    {        for (int j = 0; j < col; j++)        {            cout<<setw(5)<<element[i][j];        }        cout<<endl;    }}`

`//销毁空间    for (i = 0; i < row; i++)    {        delete []element[i];        element[i] = NULL;    }    delete []element;    element = NULL;`

## 二：vector法

`#include#include#includeusing namespace std;void main(){    int row, col;    cout<<"请输入行列值:";    cin>>row        >>col;    vector <vector<int> > test(row, vector<int>(col)); //声明一个二维数组，注意这里的空格不能少    //初始化，其实不初始化也是可以的，vector默认是0    for (int i = 0; i < row; i++)    {        for (int j = 0; j < col; j++)        {            test[i][j] = 0;        }    }    cout<<endl;    //输出值    for (i = 0; i < row; i++)    {        for (int j = 0; j < col; j++)        {            cout<<setw(5)<<test[i][j];        }        cout<<endl;    }    //输出行列值    cout<<"行:"<<test.size()<<endl;    cout<<"列:"<<test[1].size()<<endl;}`