Solution: File I/O with Name
This program demonstrates basic file handling, writing and reading data from a text file.
Explanation:
It first asks the user to enter their name.
The entered name is written to a file named
user.txtusing an output file stream.Then, it reopens the same file in read mode and retrieves the saved name.
Finally, it displays the name read from the file on the screen.
If there’s an issue opening the file for writing or reading, an error message is shown.
Solution: File I/O with Name
This program demonstrates basic file handling, writing and reading data from a text file.
Explanation:
It first asks the user to enter their name.
The entered name is written to a file named
user.txtusing an output file stream.Then, it reopens the same file in read mode and retrieves the saved name.
Finally, it displays the name read from the file on the screen.
If there’s an issue opening the file for writing or reading, an error message is shown.