定义一个3行4列的数组a

数组做法:

定义数组:
		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];
    }
}
    原文作者:allinoo
    原文地址: https://blog.csdn.net/oy0918/article/details/111130136
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞