You can use this library in your CMake project:
add_subdirectory(external/matrix_reader)
target_link_libraries(${CMAKE_PROJECT_NAME} MatrixMarketReader)
ifstream is ("/path/to_mtx");
matrix_market::reader reader (is);
if (reader)
{
auto &matrix = reader.matrix ();
auto &meta = matrix.meta;
auto col_ids = matrix.get_col_ids ();
auto row_ids = matrix.get_row_ids ();
auto data = matrix.get_dbl_data ();
for (unsigned int i = 0; i < meta.non_zero_count; i++)
{
const unsigned int col = col_ids[i];
const unsigned int row = row_ids[i];
const auto value = data[i];
}
}