c++ - Reading PPM file header (type P6), width is missing -


assuming you're reading ppm file this:

ifstream img; img.open("image.ppm", ios::binary); try {     if (img.fail())     {         throw("can't open input file");     }     string header;     int w, h, b;     img >> header;     cout << header << endl;     if (header.compare("p6") != 0)     {         throw("wrong format file. file needs p6 type!");     }     img >> w >> h >> b;     cout << w << " " << h << " " << b << endl;     if (b < 0 || b > 255)     {         throw("an error message");      }     img.ignore(256, '\n'); } catch (const char *err)  {     fprintf(stderr, "%s\n", err);     img.close(); } 

and removed width or height value in header. b value read rgb number in byte form. there possible case if-statement won't prevent program ending? in other words there optimized method prevent such errors?

one possible problem: 1. data after b binary, b in scenario non-ascii , 0, pass test error message.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -