Write a program that copies source.txt to destination.txt line by line. Open an ifstream for reading, ofstream for writing. Use getline() in a loop to read each line and << to write it.
Check if both files opened successfully before starting the copy. If opening fails, print an error and exit. This prevents copying from or to invalid streams. After the loop, both files close automatically.
Test with multi-line files to verify all content transfers. This pattern appears in backup tools, log processors, and text filters.