Write to files using << just like cout: file << "Score: " << score << "\n";. The operator converts variables to text and appends them to the file. Chain multiple << for complex output.
All formatting manipulators work: file << fixed << setprecision(2) << price; writes decimals with two digits. You control spacing, padding, and number formats like with console output.
Remember to include newlines explicitly with "\n" or endl. Unlike console output, files don't automatically line-wrap. Missing newlines create one giant line of text.