title: Why is ofstream::write adding extra bytes to the end of file?
body: <p>I'm trying to write the following bytes to a file </p>
  
  <pre><code>[03 00 01 00 FF 00 00 00 FF 00 00 00 FF]
  </code></pre>
  
  <p>but I keep getting the following bytes added to the end</p>
  
  <pre><code>[03 01 0F C0 00 08 00 A0 00 C7 00 00 00 02 00 70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
  </code></pre>
  
  <p>I've read up, and I've been told to use <code>std::ios::binary</code> when opening the file, which doesn't seem to help.
  Here's my code</p>
  
  <pre><code>#include &lt;fstream&gt; 
  #include &lt;iostream&gt;
  #include &lt;conio.h&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  int main() {
      int height = 1,
          length = 3;
      int data[] = {
          0x3,0x0,0x1,0x0,
          0xff, 0x0, 0x0,
          0x0, 0xff, 0x0,
          0x0, 0x0, 0xff
      };
  
      ofstream file("thing.dki", std::ios::binary);
      for(int i = 0; i &lt; sizeof(data); i++) {
          file.write((char*) &amp;data[i], 1);
      }
      file.close();
  
      return 0;
  }
  </code></pre>