Output on the Printer:
The output of the program can also he sent directly to the printer attached with the computer. Usually the printer is connected to the first parallel port. The first parallel port is called “PRN” or “LPT 1”.
To send the output to the Printer, an output object of ofstream (or fstream) is created and the printer port is assigned to it, e.g.
Where
PRN: represents the first parallel port. It may be “LPT1”. Similarly, the second parallel port is indicated by “LPT2” and so on.
In the above statement the object pout of ofstream is created and the first parallel port is assigned to it. All the output sent through “pout” object is sent to the printer attached to the “PRN” port.
Program:
Write a program to send a message on the printer attached to the parallel port “PRN”.
#include <iostream.h>
#include <stdlib.h>
main( )
{
of stream ppp( “PRN” );
ppp << “I love Internet”<< endl;
ppp << “Internet is the way of communication ” << endl;
ppp.put( ‘\x0C’ );
}
In the above program, the first two statements will print the message of two lines on the printer. The third statement having the code ‘\x0C’ will eject the page from the printer after printing the message on the paper.
comment closed