<p>In C++ I'd like to do something like:</p>

<pre><code>int n = get_int_from_user();

char* matrix = new char[n][n];

matrix[0][0] = 'c';
//...
matrix[n][n] = 'a';

delete [][] matrix;
</code></pre>

<p>but of course this doesn't work.  What is the best way to do something similar?  I've seen some solutions to this but they seem pretty messy.</p>

For a true two dimensional array:
```
```
int n = get_int_from_user();

char** matrix = new char*[n];
for (int i = 0; i < n; i++) {
    matrix[i] = new char[n];
}

// Operations on matrix.

for (int i = 0; i < n; i++) {
    delete [] matrix[i];
}
delete matrix;
```
```
Just off the top of my head. Mistakes, no doubt. However, other people have posted a more elegant approach, I think.