Thread: Stream to LPT?

  1. #1

    Stream to LPT?

    How can I make a stream go to a printer on an LPT port? Can it be done?

    If not, is there any other way of outputting to an LPT?

  2. #2
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    #include <iostream>
    #include <fstream>
    #include <stdlib>
    using namespace std ;
    int main()
            char printer[10] = "LPT1:";
            char character;
            ofstream prnt (printer);
            if ( 
                    cout << "ERROR-Unable to open " << printer << '\n' ;
                    return 1 ;
            system ("cls");
            cout << "Type the text you wish to have printed.  You must use "
                 << "\nyour own returns as there is no text wrapping other than "
                 << "\nthat which the printer will do at the end of page. Though, "
                 << "\nthis may lead to words being cut in half.  This simple "
                 << "\nprogram could be made much better utilizing iomanip for text "
                 << "\nformatting, but it shows you the basics of opening a printer "
                 << "\nport. " << endl << endl
                 << "Press a '#' and return when you are ready to print... " << endl
                 << endl << endl;
            while (character != '#')
                    if(character != '#')
            prnt << '\r' << '\f' ; // return and eject the last page from the printer
    Last edited by Betazep; 02-04-2002 at 03:07 PM.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    You can get a handle to the port with the CreateFile() API function, look it up in the help with particular reference to the sections dealing with "communication resources". Once you have a handle, you can use any of the normal handle based I/O functions in the API.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    I tried to use _bios_printer(); function before, but the only thing I could do is turn my printer on, using _bios_printer(_Init_Printer,0,0);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New stream flushing FAQ candidate?
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 07-01-2009, 05:57 PM
  2. Stream Server
    By ch4 in forum Networking/Device Communication
    Replies: 18
    Last Post: 06-29-2009, 03:09 PM
  3. Discard wrong data from stream
    By mesmer in forum C Programming
    Replies: 7
    Last Post: 11-16-2008, 02:30 AM
  4. Closing a stream
    By cunnus88 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2008, 05:15 PM
  5. Help! About text stream and binary stream
    By Antigloss in forum C Programming
    Replies: 1
    Last Post: 09-01-2005, 08:40 AM