// 二维动态数组.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>
    using namespace std;

    typedef int* IntArrayPtr;

    int main(int argc, char* argv[])
    {
       int d1 = 0, d2 = 0;
       cout <<"Enter the row and column dimensions of the array:\n";
       cin >>d1 >>d2;

       IntArrayPtr *m = new IntArrayPtr[d1];    //含有d1个指针的数组,每一个指针都指向一个int型的动态数组
       int i = 0, j = 0;
       for(; i < d1; ++i)
          m[i] = new int[d2];
       //m现在为d1行d2列的二维数组

       cout <<"\nEnter " << d1 <<" rows of " << d2 <<" integers each:\n";
       for(i = 0; i < d1; ++i)
          for(j = 0; j < d2; ++j)
             cin >>m[i ][j ];

       cout <<"\nEchoing the two-dimensional array:\n";
       for(i = 0; i < d1; ++i)
       {
          for(j = 0; j < d2; ++j)
             cout <<m[i ][j ] <<' ';
          cout <<endl;
       }

    

      for(i = 0; i < d1; ++i)

        delete[] m[i];

      delete[] m;

       return 0;
    }

 

    

    

 

 

 posted on 2012-05-04 14:05  飞翔@骑士  阅读(110)  评论(0)    收藏  举报