Yes you can, Your code should be:
ofstream printer;
printer.open("lpt1");
I believe it's case sensitive(not sure "lpt1" or "LPT1"). Also, you'll need to write a page eject command.
EDIT:
LPT (Line Print Terminal) is name of the parallel port interface on IBM PC-compatible computers. Over the years, the parallel port interface has decreased use because of the rise of Universal Serial Bus.
In DOS, the parallel ports could be accessed directly on the command line. For example, the command type c:\autoexec.bat > LPT1 would direct the contents of the autoexec.bat file to the printer port(recognized by the reserved word LPT1"). A PRN device was also available as an alias for LPT1.
Microsoft Windows still refers to the ports in this manner in many cases, though this is often fairly hidden.
In the Linux operating system the first LPT port is available via the filesystem as /dev/lp0.
To write to a printer, one should simply open the printer as if it were a file (the printer name is system-dependent; on Windows machines, it will be lpt1 or prn, while on unix machines, it will be something like /dev/lp), then write whatever text has to be written.
Sample program could be as simple as:
std::ofstream print;
print.open("LPT1");
if (!print)
return 0;
print << data;
print.close();