Put Function in C++:
The “put” function is used to write a single character at a time into formatted (or sequential) input/output file.
The syntax of this member function is:
Where:
Object: represents an object of ofstream (or fstream) class.
Put: represents a member function of the object.
Character: represents a single character that is to be written into the files. It may be a variable or character constant.
Program:
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
#include <stdlib.h>
main ( )
{
char ch;
ofstream ppp (“data.txt”);
clrsrc ( );
if (!ppp)
{
cerr << “File opening error” << endl;
exit (1);
}
while (ch!=27)
{
ch=getche ( );
ppp.put (ch);
if (ch=’\r’) cout << endl;
}
}

comment closed