开发者

make one arrays content into another 2d arrays rows & colums

I have this function that reads a textfile and sends the strings to an array and then from that function I send that array and number of elements to my constructor. Now my constructor creates a dynamic 2d-array(I hope). I would like my 2d-arrays rows and columns to be assigned values from the array received.

heres my constructor.

Graph::Graph(string cities[], int n)
{
     this->nrOfCities=n;
     this->x=n;
     this->y=n;
     this->graph=new string *[x];
     for (int i = 0; i < x; i++) 
        this->graph[i] =new string[y];
     for(int i=0;i<this->x;i++)
        fo开发者_如何学Cr(int j=0;j<this->x;j++)
           this->graph[j]=NULL;
     for(int i=0;i<=this->x;i++)//I know this last part doesn't work.
         for(int j=0;j<this->x;j++)
             this->graph[0][j+1]=cities[j];
}

Any kind of help is appreciated.


In order to make a dynamic 2darray you must try s.th. like this:

type** arr2d;
arr2d = new type*[rows];
for(int i=0; i<rows; ++i)
  arr2d[i] = new type[cols];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜