I read from the .BMP file an array of pixels that is correct in size, according to the file header.
void img::read_bimg(char ** &smth, unsigned int bfOfBits, unsigned int biX, unsigned int biY) // biX, biY (512) - высота и ширина в //пикселях, в соответствии с заголовком файла. // bfOFBits (1078) - начало пикселей в файле. { imgf.seekg(bfOfBits, std::ios::beg); std::cout << imgf.tellg() << std::endl; // Выдает 1078, что верно. // С этого места начинаются сами пиксели. for (unsigned int y = 0 ; y < biY ; y++) { for (unsigned int x = 0; x < biX ; x++) { unsigned char buf; imgf.read((char*)&buf, sizeof(char)); smth[y][x] = buf; } } std::cout<< imgf.tellg() << std::endl; // -1 } I always returned -1 when tellg , which is why I thought that was the end of the file, that is, the eofbit flag. But checking with a simple move:
imgf.seekg(0, std::ios::end); imgf.tellg; Got a value of 263222 , which is slightly more (512*512) . So the end of the file can not be, most likely it is a failbit . But what could the program have encountered in a file such that an error flag was set in the stream?
As well as using the clear() crutch, I drop the flag and get rid of this error .
UPD : The file was opened without the binary flag.
biX, biY (512). - D Thr.