In C++, I need to write to an existing file and keep the previous content there.
This is what I have done:
std::ofstream logging;
logging.open(FILENAME);
logging << "HELLO\n";
logging.close();
but then my previous text is overwritten (gone). What did I do wrong?
Thanks in advance.
logging.open(FILENAME, std::ios_base::app);
You have to open the file in append mode:
logging.open(FILENAME, std::ios::app);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With