[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

How to Print to Printer from g++ program?

As a physicist I wrote large programs in Pascal before retiring in 1994 but nothing since until last week. I thought of a problem I wanted to solve, read up on C++ and got my program working with only a few struggles with syntax but how to write directly to the printer has eluded me. I could open a disk file, write the output to disk and then print the file. This would get the job done but this seems awkward. My references suggested redirection so I piped the console output to the printer. My poor old laser printer went wild and I had shut the system down - the only way I know to flush the printer buffer is to re-boot. When I re-booted, the printer then spit out a perfect copy of the console output. There was also a statement in the references to the effect that a printer is just another file system. Perhaps it is as simple as ofstream out_file ("/dev/lpt0"); ? But what if the printer talks back? I know when I wrote those Pascal programs I distributed them to people with different printers. The programs could check printer capabilities and print excellent graphs if they found a postscript printer. I haven't the foggiest recollection of how I programed this.

If this question is regarded as wildly off target for this list, for the record I tried a Google search for c++ forum and found essentially the same question posted last December at cittoolbox.com. There were no responses.

Tom George

Reply to: