Yes you can, your code should be:
ofstream printer; printer.open("lpt1");
I find it case sensitive (not sure about “lpt1” or “LPT1”). In addition, you need to write a page retrieval command.
EDIT:
LPT (Line Print Terminal) is the name of the parallel port interface on IBM PC compatible computers. Over the years, the parallel port interface has been decreasing due to the growth of the universal serial bus.
In DOS , parallel ports can be accessed directly on the command line. For example, the command type c:\autoexec.bat > LPT1 will direct the contents of the autoexec.bat file to the printer port (recognized by the reserved word LPT1). The PRN device was also available as an alias for LPT1.
Microsoft Windows still treats ports this way in many cases, although this is often quite hidden.
On Linux first LPT port is accessible via the file system as /dev/lp0 .
To write to the printer, you just need to open the printer as if it were a file (the name of the printer depends on the system; on Windows machines it will be lpt1 or PRN , and on Unix machines it will be something like /dev/lp ), then write what text should be written.
An example program might be simple:
std::ofstream print; print.open("LPT1"); if (!print) return 0; print << data; print.close();
Alok save
source share