ofstream stands for output file stream, your tool for writing data to files. Declare ofstream file("output.txt");, and it creates output.txt (or overwrites it if it exists). By default, opening for writing clears the file.
You write with << just like cout: file << "Hello\n"; writes text to the file. The stream buffers output and flushes when you close it or the buffer fills. Data isn't guaranteed on disk until you close the stream or call flush().
If your program crashes before closing, you might lose buffered writes. Always close files when done.