If the intention is to allocate a contiguous array of fixed-length char arrays (what you call a 2D char array), the syntax isn't terrible. The row width must be a compile-time constant, but the number of rows can be arbitrary. Given some arbitrary primary dimension n
and some fixed size row-width M
, you would do it like this:
char (*p)[M] = new char[n][M];
and delete it like this when no longer needed:
delete [] p;
Access to any buffer i
from 0..n-1 is done as:
p[i]
such as copying "foo" to the third row:
std::strcpy(p[2], "foo");
just as you would with a regular fixed array of arrays.
That said, I would advise that unless you have a compelling reason to do otherwise (some specific odd legacy API or some such) that you use the standard library containers. They really are the cats whiskers. At a minimum you should use smart pointers, as raw pointers should not own resources.
Hope it helps (particularly heeding the last paragraph).