Reputation: 191
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.
Upvotes: 1
Views: 5100
Reputation: 3119
ofstream myfile ("ex.txt", ios_base::app);
will open a file in append mode. Each write operation will append to the existing contents.
Upvotes: 2