* "TJB" <ce*******@telia.com> schriebt:
"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com...
I want to use "new" to build an array test[1000][1000]. Can you tell me
how to do?
You have to create an array of arrays like this:
int i,**test;
test = new int*[1000];
for (i = 0; i < 1000; i++)
test[i] = new int[1000];
You could also start with an array of pointers, int* test[1000], and
initialize the elements in it.
Well no, e doesn't "have to".
Except if e _really_ doesn't want a two-dimensional array.
See the answer from osmium earlier in the thread about how to allocate
a two-dimensional array using new,
int (*p)[1000] = new int[1000][1000];
The general question is also a FAQ, see
<url: http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.15>,
"How do I allocate a multidimensional array using new?"
Unfortunately, in spite of the heading the FAQ does not show how to allocate
a multidimensional array using new (!), only jagged arrays like yours. But
it does go on to show a few generally much better ways.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?