Printers and Portability

This is a discussion on Printers and Portability within the C++ Programming forums, part of the General Programming Boards category; I was wondering if there was a good portable way to send information to a printer? Using fstreams will not ...

  1. #1
    Master of Puppets rwmarsh's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    96

    Printers and Portability

    I was wondering if there was a good portable way to send information to a printer? Using fstreams will not work with my setup (windows xp and an ink jet printer) and the only other way I know of is with windows api's which (correct me if I am wrong) will only work on a windows OS.

    I have been playing with pdCurses and I like it so far. I would like to start using it on a regular basis but I have not seen anything on printer functions for it and I would hate to have to #include <windows.h> just so that I can send text to the printer.
    Using DEV-C++ Under Windows XP
    +------------------------------+

    "No! Do, or Do Not. There is no Try..."

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,439
    Assuming you have a printer connected to the LPT1 port, you create an ofstream object and open lpt1.
    Code:
    ofstream printer("lpt1");
    EDIT: Oh... you said portable... I'm not sure if lpt1 is recognized as a printer port under other systems. Most probably not.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    > I was wondering if there was a good portable way to send information to a printer?
    There is no standard device name for a printer, nor is there a standard way of finding out if you've even got a printer.
    Not to mention the vast variety of printers and printer languages (PCL, Postscript, ... )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Try one of the cross-platform UI frameworks like Qt, GTK+ or wxWidgets. They ought to provide printing.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    FYI - Some printers have a special secret protocol that requires you to use the Windows driver (and WinAPI). I have a cheap Canon ink jet, and it doesn't respond if you simply it send ASCII. It won't work with DOS applications at all.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21