A proper way to create a matrix in c++

后端 未结 10 2367
無奈伤痛
無奈伤痛 2020-11-27 05:33

I want to create an adjacency matrix for a graph. Since I read it is not safe to use arrays of the form matrix[x][y] because they don\'t check for range, I deci

10条回答
  •  情话喂你
    2020-11-27 06:32

    Probably, not relevant as this is an old question, but you can use the Armadillo library, which provides many linear algebra oriented data types and functions.

    Below is an example for your specific problem:

    // In C++11
    Mat matrix = {  
        { true, true},
        { false, false},
    };
    
    // In C++98
    Mat matrix;
    matrix << true << true << endr
           << false << false << endr;
    

提交回复
热议问题