Matrix with unknown dimension

Hi

I try to write code for one problem which is worked with the matrix.I have written in specific size 5 by 5 and I know the general formula for these matrix based on dimension,I want to write a general form that take the matrix size and then create my favor matrix.However,when I write like below the following error is appeared

int m;
cin>>m;
int A[m][m];

Error: m must be constant

can anyone can help me.

thanks
std::vector<> http://www.mochima.com/tutorials/vectors.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <vector>

std::vector< std::vector<int> > create_square_matrix( std::size_t m )
{ return std::vector< std::vector<int> >( m, std::vector<int>(m) ) ; }

int main()
{
    int m;
    std::cin >> m;

    auto A = create_square_matrix(m) ;

    for( int i = 0 ; i < m ; ++i )
    {
        for( int j = 0 ; j < m ; ++j ) std::cout << A[i][j] << ' ' ;
        std::cout << '\n' ;
    }
}

http://coliru.stacked-crooked.com/a/46ea2df45402e0b1
Topic archived. No new replies allowed.