Create Array of Variable Length, Depending on Contents of File

I have a file that is formatted in a certain way. Here is an example:
"input.txt":

1
2
3
4
6 3
A B C D E F
G H I J K L
M N O P Q R


The first two numbers at the top are the width and height of the matrix of characters. I want to make an 2-dimensional array for these chars, with the 2 numbers at the top as the dimensions of the array. So for example, in this file I would want

char[6][3] charMatrix

I've tried using this code:
1
2
3
4
    ifstream fin ("input.txt");
    int width, int height;
    fin >> width >> height;
    char charMatrix[width][height];

But it says:
Error: expression must have a constant value

How can I fix this (or work around it)?
Last edited on
use a vector of vectors of char, a vector of string , or a matrix class. What do you need an array for?
you can't define an array with a certain size during runtime.
just use a vector or an array, which is big enough, and skip the first line.
Topic archived. No new replies allowed.