i made this little code to read char by char the 120 first bytes of a binary file :
int main(){
string filename("kodim23.qoi");
ifstream image_file(filename); //open file
if (!image_file.is_open()) { //check if file is open
cerr << "Could not open the file - '"
<< filename << "'" << endl;
return EXIT_FAILURE;
}
for (int q = 0;q<120;q++) //read char by char and display them as int
{
cout << q << " : ";
cout << int(image_file.get()) << endl;
}
image_file.close(); //close file
return 0;
}
I get an expected output for q in range 0 to 114 and then just -1 forever (i tried to increase q it's always -1) : console output.
I tried to open the file with frhed (an hexadecimal editor) to check what happens at offset 115, but there is nothing weird : frhed output.
As you can see at offset 114 there is 0x54 (84), so my program is working as expected and then at offset 115 there is 0x1a (90) and my program output is -1...
Do you know what could be wrong ?