I'm trying to assign values to a 2d vector in c ++ This is how it is defined, where rows and columns are integers defined.
vector < vector <int>> vec(filas , vector <int> (columnas));
what I want to assign to each space of the vector are characters that are in a pbm file that clearly contains only ones and zeros
char i;
FILE* file;
file = fopen("archivo.pbm", "r");
then in this way I am passing values to each of its "boxes",
for (int h=0; h<filas; h++){
for (int j=0; j<columnas; j++){
while((i=fgetc(file))!=EOF){
vec[h][j] = i;
}
}
}
but then when printing on the screen the values of the vector, it turns out that it only contains zeros and curiously in vec [0] [0], stores a '10'
for (int h=0; h<filas; h++){
for (int j=0; j<columnas; j++)
cout << vec[h][j];
cout <<endl;
}
fclose(file);
if someone could tell me why by assigning the values in this way, it does not turn out in advance thank you very much!
vec[h][j] = i;