The function put() writes a single character to the associated stream. Similarly, the function get() reads a single character from the associated stream. The program requests for a string. On receiving the string, the program writes it, character by character, to the file using the put() function in a for loop, Note that the length of the string is used to terminate the for loop.
The program then displays the contents of the file on the screen. It uses the function get() to fetch a character from the file and continues to do so until the end=of-file condition is reached. The character read from the file is displayed on the screen using the operator <<.