title: C++ Write string to beginning of file
body: <p>I have a file that is like</p>
  <blockquote>
  <p>This is line 1</p>
  <p>This is line 2</p>
  </blockquote>
  <p>and I have a string <code>This is line 0</code>. How do I write this string into the beginning of the file so the contents of the file is now:</p>
  <blockquote>
  <p>This is line 0</p>
  <p>This is line 1</p>
  <p>This is line 2</p>
  </blockquote>
  <p>I currently have</p>
  <pre><code>ifstream myfile(&quot;lunch.txt&quot;);
  myfile.seekg(0,ios::beg);
  myfile &lt;&lt; &quot;This is line 0&quot;;
  </code></pre>
  <p>But it is not working as expected.</p>