Tried to write a simple PPM image file in C++, here is the code:
#include <iostream>
const int image_height = 256, image_width = 256;
int main()
{
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
for (int i = image_height - 1; 0 <= i; --i) {
for (int j = 0; j < image_width; ++j) {
int red = j; int green = i; int blue = 63;
std::cout << red << ' ' << green << ' ' << blue << '\n';
}
}
return 0;
}
I compiled it and then redirected the output to a file named "image.ppm". I tried to open it with GIMP but it failed. It says that it is an invalid file. The GIMP that I have is the latest version and I have checked the PPM file format; what I wrote does seem to conform with the general format. So what am I doing wrong?