title: Writing bytes to a file
body: <p>I have an array of bytes defined as :</p>
  
  <p><code>unsigned char * pixels = new unsigned char[pixelsLen];</code></p>
  
  <p>and I want write all bytes from this array to a <code>.bmp</code> file. </p>
  
  <p>This is how it does not work:</p>
  
  <pre><code>ifstream screen ( "input.bmp", ios::binary | ios::in );
  ofstream output ( "output.bmp", ios::binary | ios::out | ios::app );
  output.write( ( char * )&amp;pixels, pixelsLen );
  output.close();
  </code></pre>
  
  <p>This is how it does work :</p>
  
  <pre><code>ifstream screen ( "input.bmp", ios::binary | ios::in );
  ofstream output ( "output.bmp", ios::binary | ios::out | ios::app );
  for ( size_t i = 0; i &lt; pixelsLen; i++ ) {
      output.write( ( char * )&amp;pixels[i], 1 );
  }
  output.close();
  </code></pre>
  
  <p>The question is why it works when I'm writing it byte by byte and does not work when I'm trying to write it at once ?</p>