Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Dynamic allocation of two dimensional array

Feb 21, 2006 9:45AM PST

I am having trouble set the pointer to a two dimensional array. I have seen example of one
dimensional array but not two. This is what I am
Working with. Oh you can email me at lorindia@earthlink.net if you have a solution.

double factor;
double HalfArray[30][41];


ifstream infile(path2, ios::binary | ios::in);
if(!infile) cout << " Array HalfArray not built" <<
endl;
for(i = 0; i < 30; i++) {
for(j = 0; j < 41; j++){
infile.read((char*)&factor, sizeof(factor));
HalfArray[j] = factor;
}//End of J loop
}//End of I loop

This do not work
double HalfArray[30][41];
double *Half = HalfArray;
Or
Double *Half = new Double[30][41];

Discussion is locked

- Collapse -
Here is your code example.
Feb 21, 2006 10:57AM PST
- Collapse -
(NT) (NT) For a 2D array it should be "HalfArray[i][j] = factor;"
Feb 21, 2006 11:04AM PST