title: Reading bytes from a P6 PPM file into a character array (C++)
body: <p>Here is the relevant code:</p>
  
  <pre><code>string s;
  int width, height, max;
  
  // read header
  ifstream infile( "file.ppm" );  // open input file
  infile &gt;&gt; s; // store "P6"
  infile &gt;&gt; width &gt;&gt; height &gt;&gt; max; // store width and height of image
  infile.get(); // ignore garbage before bytes start
  
  // read RGBs
  int size = width*height*3;
  char * temp = new char[size]; // create the array for the byte values to go into
  infile.read(temp, size); // fill the array
  
  // print for debugging
  int i = 0;
  while (i &lt; size) {
      cout &lt;&lt; "i is " &lt;&lt; i &lt;&lt; "; value is " &lt;&lt; temp[i] &lt;&lt; endl;
      i++;
  }
  </code></pre>
  
  <p>Then, the output that I get says that the values in the array are either blank, or "?". I guess this means the bytes were not converted into chars properly?</p>
  
  <blockquote>
    <p>i is 0; value is </p>
    
    <p>i is 1; value is </p>
    
    <p>i is 2; value is </p>
    
    <p>i is 3; value is ?</p>
    
    <p>i is 4; value is ?</p>
  </blockquote>
  
  <p>...etc. </p>