As was mentioned in the previous reply, you where trying to file.read
with a null pointer.
I see that you are trying to load the whole file into memory, then do some pointer arithmetics to work with the data. But why not just read the BITMAPFILEHEADER
directly instead?
ifstream file("lena.bmp");
// read in the header:
BITMAPFILEHEADER header;
file.read(reinterpret_cast<char *>(&header), sizeof(header));
// validate the header, get the size in bytes of the bitmap data
size_t bitmapSizeBytes = width * height * channels; // or something like that...
// Now read the bitmap. Use a vector to simplify memory management:
std::vector<unsigned char> bitmap;
bitmap.resize(bitmapSizeBytes);
file.read(reinterpret_cast<char *>(&bitmap[0]), bitmapSizeBytes);