1

I have an existing txt file, I want to be able to write stuff to it (on the next line) without modifying the existing contents. What's a good way to do this?

#include <iostream>
ofstream myfile ("ex.txt"); 

seems to clear all the existing text.

1
  • 1
    I recommend you read more about the open function, or the constructor. Commented Aug 1, 2012 at 6:55

2 Answers 2

2

ofstream myfile ("ex.txt", ios_base::app); will open a file in append mode. Each write operation will append to the existing contents.

Sign up to request clarification or add additional context in comments.

Comments

1

Open the file using the ios_base::app flag

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.