The problem with my code is that it never gets into the if. In other words it never reads the '\n' character. The '\n' exists in the file I want to read and it is important to read it in order to save the matrix the right way.
#include <iostream>
#include <cstring>
#include <fstream>
#include <iomanip>
using namespace std;
int main(int argc, char **argv){
int N, M;
int n, m;
int i, j;
char a;
ifstream myfile;
string txt;
char mat[1000][1000];
txt = argv[1];
myfile.open(txt);
n = 0;
m = 0;
while(myfile >> a){
if(a == '\n'){
n++;
m = 0;
continue;
}
mat[n][m] = a;
m++;
}
myfile.close();
cout << n << " " << m;
for(i=0; i<=n; i++){
cout << endl;
for(j=0; j<m; j++){
cout << mat[i][j] << " ";
}
}
}