title: C++: reading large pgm file with ifstream
body: <p>I want to load a 16-bit binary PGM image with a size of 4096x4096 pixels using std::ifstream. The problem is that I can only load smaller files, eg. 512x512. If I try to load the "large" one the data I get is always 0 for every pixel.  </p>
  
  <p>Example Code:</p>
  
  <pre><code>int size = width*height;
  unsigned short* data = new unsigned short[size];
  
  // Read the terrain data
  for(int i = 0; i &lt; size; i++)
  {
      file &gt;&gt; data[i];
  }
  </code></pre>
  
  <p>If I set size manually to a lower value, this seems to work. Any idea?</p>
  
  <p>Thx Tim</p>