To add data without erasing old content, use ios::app: ofstream file("log.txt", ios::app);. Every write goes to the end of the file. The file grows instead of being replaced. This mode is perfect for logs where you want to keep history.
Each run of your program adds new entries without losing previous ones. The file position starts at the end automatically. You can't move the write position backward in append mode, seekp() is ignored.
If you need random access writing, use ios::out without ios::app, but remember this truncates the file on open.