Hi,
I'm making an image editor and I'm having problems with the get() command while reading a file.
First, here's the part of the code I have problems with :
Code:
//image.h
class Image{
public:
//...
protected:
int fileType,
width,
height;
float** tab;
//...
}
//image.cpp
float Image::readChar(ifstream& input){
char charTemp;
float floatTemp;
input.get(charTemp);
floatTemp = (float) charTemp;
//...
return floatTemp;
};
void Image::readImage(ifstream& input){
readHeader(input); //this reads the header of the file
int k, l;
tab = new float*[getHeight()];
for(int j=0; j<height; j++) tab[j] = new float[getWidth()];
if(fileType == 5 || fileType == 6){
for(k = 0; k<height; k++)
for(l = 0; l<width; l++){
tabR[k][l] = readChar(input);
}
}
//...
};
The file i'm reading is a pgm (portable greymap).
The problem is when I try to read a file witch have the 26th ASCII character, input.get(charTemp) gets the ASCII number 31 and then act as if the file has ended (even if there's more than 200 ASCIIs left in the file after that character).
example : ")#¬" would be read as 41, 35, 31, 204, 204, 204 instead of 41, 35, 31, 26, 29, 172
(I tested a few thing and input.eof() always returns true)
Anyone have an idea of why this is happening and what I should do?
Thanks
Jonathan