Read a matrix from txt file into matrix in c++ -



Read a matrix from txt file into matrix in c++ -

i'm trying read in matrix txt file , recreate matrix c++. have initiate matrix in code, , trying read in each element txt file, , place in right spot.

my matrix in txt file: [1 4 5 6; 5 9 9 8; 5 2 5 6; 4 5 8 6]

i have empty 4x4 matrix called adj_matrix, , txt file called input_data.

after opening txt file , checking ifstream works, have tried:

input_data >> adj_matrix[i][j]

i error using square brackets [i][j], ideas?

the error is:

error 4 error c2088: '[' : illegal class

here code

while (!input_data.eof()) // while not @ end-of-file { getline(input_data, row_grab); if (matrix_check = 1) { input_data >> adj_matrix[i][j]; cout << row_grab; j++; } i++;

this adj_matrix code:

int matrix_dim = node_list.size(); vector<vector<int>> adj_matrix; adj_matrix.resize(matrix_dim); //set 1 dimension right size // loop resize sec dimension (int = 0; < node_list.size(); i++) { adj_matrix[i].resize(matrix_dim); }

c++ matrix ifstream

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -