I am attempting to read a PPM image from standard input with this code:
cin >> format;
cin >> ppm->width >> ppm->height >> ppm->colourMax;
for (int r = 0; r < ppm->height; r++) {
ppm->pixels[r] = new Pixel[ppm->width];
for (int c = 0; c < ppm->width; c++) {
Pixel p = Pixel();
cin.read(reinterpret_cast<char *>(&p.r), sizeof(unsigned char));
cin.read(reinterpret_cast<char *>(&p.g), sizeof(unsigned char));
cin.read(reinterpret_cast<char *>(&p.b), sizeof(unsigned char));
ppm->pixels[r][c] = p;
}
}
However, when I output the PPM image unchanged, I am missing the very last pixel. Everything else seems to work perfectly. Any ideas?