1. ## About an indefinite matrix

Hi to All,

I need to fill a matrix as this:
Code:
`char mat [N] [N]`
N is an integer, that I don't know.
In my program I have a construct for its Input as this.
Code:
`cin >> N;`
Can work this scenario ?

For Example can work this program?
Code:
```#include <iostream.h>

int main()
{
int N;  /max element for Matrix
char mat[N][N];
int i, j; /Counters

cout << 'Enter the number of Rows and Colums ';
cin >> N;
cout << endl;

cout << 'Enter the Matrix elements ' << endl;

for (i=0; i<N; i++)
{
for (j=0; j<N; j++)
cout << mat[i][j];
cout << endl;
}
cout << endl;

}```
This code is correct ? How can resolve my problem ?

Thank you for help. Be patient with me; I am new in c++ programming.

Best Regards

2. 1. use <iostream>
2. use vector of vectors
3. Check value entered by the user before using it
4. Don't use variables without initializing them

3. Originally Posted by vart
2. use vector of vectors
Hi,
Thank You for fast reply.
Please, what is vector of vectors ?
Have You a sample or a link, in order to learn this concept ?

Best Regards

4. Please, what is vector of vectors ?
In your context, it would be:
Code:
`std::vector<std::vector<char> > mat;`
You would need to #include <vector>, of course.

5. If you still want to use your char array you must make it dynamic otherwise your compiler expects a constant.
For example:

Code:
```cin >> N;
char** mat = new char*[N];
for(int i=0;i<N;i++)
mat[i] = new char[N];```

Popular pages Recent additions