Create an ofstream to write: ofstream output("results.txt");. This creates results.txt if it doesn't exist or truncates it to zero bytes if it does. You lose all previous content unless you specify append mode.
You can also open later: output.open("results.txt");. If opening fails (bad permissions, disk full), the stream enters a fail state. Check if(output) before writing to avoid silent failures.
The default behavior (truncating existing files) catches beginners off guard. If you want to preserve old data, use append mode with ios::app flag. Otherwise, opening overwrites everything.