The function get () is a member function of the file stream class f stream, and is used to read a single character from the file. The function put () is a member function of the output stream class f stream, and is used to write a single character from the output file. The programme give below reads strings from the standard input device, and writes the same to a file character by character. A sequential file is developed and its pointer is placed at the start of the file. It is processed in sequence till the end of file is reached.
Programme in C++, writes and reads characters from the file
# include < f. Stream .h >
Void main ()
{
Char C, string [75];
F stream file ("student. Txt", ios : : in / ios : : out);
Cout << "enter string :";
Cin. Get line (string, 74);
For (Int I = 0, string [I]; I++)
File. Put (string [I]); // writes a character
File. Seek g (0); // seek to the beginning
Cout << "output string : ";
While (file) // reads a character
{
File. Get (C);
Cout << c;
}
}