title: Write to the middle of an existing binary file c++
body: <p>I'm trying to open a binary file for writing without erasing the content. But I do not want to write to eof. I want to write to a specific position in file. </p>
  
  <p>Here is a litte example:</p>
  
  <pre><code>ofstream out("test.txt", ios::binary | ios::app);
  for(int i = 0; i &lt; 100; i++)
      out.put('_');
  out.write("Hallo", 5);
  out.close();
  
  ofstream out2("test.txt", ios::binary | ios::app);
  out2.seekp(10);
  out2.write("Welt", 4);
  out2.close();
  </code></pre>
  
  <p>If using app, seek doesn't work. If not using app opening file erases data. Does anybody know an answer?</p>