数组做法:
定义数组:
int**a = new int*[3];
for (int i = 0;i < 3;i++)
{
a[i] = new int[4];
}
for (int i = 0;i < 3;i++)
{
for (int j = 0;j < 4;j++)
{
cin >> a[i][j];
}
}
释放内存:
for (int i = 0;i < 3;i++)
{
delete[]a[i];
}
delete[]a;
vector容器做法:
int n = 3, m = 4;
vector<vector<int> > a(n, vector<int>(m)); //定义二维动态数组3行4列
for (int i = 0; i < a.size(); i++)//输入二维动态数组
{
for (int j = 0;j < a[i].size();j++)
{
cin >> a[i][j];
}
}