title: c++ / Append data on a txt file in a specific way
body: <p>I have a txt file like this:</p>
  <blockquote>
  <p>123456</p>
  <p>123456</p>
  <p>abcdef</p>
  <p>...</p>
  </blockquote>
  <p>With C++, I would like to open it and add data in the following way</p>
  <blockquote>
  <p>123456 new data new data</p>
  <p>123456 new data new data</p>
  <p>abcdef new data new data</p>
  <p>...</p>
  </blockquote>
  <p>I already saw this <a href="https://stackoverflow.com/questions/28855043/append-in-each-line-of-a-txt-file-a-specific-string-using-python">post</a> on stackOverflow but it's in Python.</p>
  <p>I used this function</p>
  <pre><code>std::ofstream file_to_save;
  file_to_save.open(path, ios::out | ios::app);
  </code></pre>
  <p>but it adds the data at the end of the file and not next to each word.</p>
  <p><strong>EDIT:</strong> Actually I add the date continuously in a loop and not everything in one time. That's the difficulty. So I have my file with all the date then inside a loop, I create new data. Let's say &quot;new data&quot; and then I would like to assign this new data (always different) to the file which already exist.</p>
  <blockquote>
  <p>123456</p>
  <p>123456</p>
  <p>abcdef</p>
  <p>...</p>
  </blockquote>
  <p>I create new data in my loop &quot;new data 1&quot; then want to add to the file like that</p>
  <blockquote>
  <p>123456 new data 1</p>
  <p>123456</p>
  <p>abcdef</p>
  <p>...</p>
  </blockquote>
  <p>Then Step 2 on my loop, I create &quot;new data 2&quot; then want to add to the file like that</p>
  <blockquote>
  <p>123456 new data 1</p>
  <p>123456 new data 2</p>
  <p>abcdef</p>
  <p>...</p>
  </blockquote>
  <p>Then Step 3 on my loop, I create &quot;new data 3&quot; then want to add to the file like that</p>
  <blockquote>
  <p>123456 new data 1</p>
  <p>123456 new data 2</p>
  <p>abcdef new data 3</p>
  <p>...
  and so on, until fill the entire file.</p>
  </blockquote>
  <p>Can someone help me ?</p>
  <p>Thank</p>