Thread: printer in w2k

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    104

    printer in w2k

    Hi!

    How do I print on my printer (LPT1), in Win2000?

    Thanks!
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  2. #2
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Do you mean in C++ like printing console aplications and text files or do you mean literally...

    how do you print.

    I hope you know the latter. This should do it...


    Code:
    
    #include <iostream>
    #include <fstream>
    #include <stdlib>
    using namespace std ;
    
    int main()
    {
    
            char printer[10] = "LPT1:";
            char character;
    
            
            ofstream prnt (printer);
    
    
            if (! prnt) 
            {
                    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 != '#')
            {
                    cin.get(character);
    
                    if(character != '#')
                       prnt.put(character);
            }
            
    
            prnt << '\r' << '\f' ; // return and eject the last page from the printer
    
    
            prnt.close();
    
    return(0);
    
    }
    Blue

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    Hi!

    The code ain't work it just don't print...
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  4. #4
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    It works... it may not work with WIN2K. I do not have 2K installed anymore. So I can't test it....

    I guess I cannot help you.
    Blue

  5. #5
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    prnt << '\r' << '\f' ; // return and eject the last page from the printer
    hi, I was just wondering what "\r" and "\f" do.

    Thanks
    -Chris

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    \r Carriage return (goes to the start of the line)

    \f Form feed (eject the sheet and feed in the next one)
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bluetooth printer
    By Opariti in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-01-2009, 11:13 AM
  2. Set Printer Prior To Loading Print Dialog Box
    By Beaner in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2008, 01:02 PM
  3. changing property (layout) of a printer
    By leojose in forum Windows Programming
    Replies: 5
    Last Post: 12-05-2005, 07:16 AM
  4. printer gone crazy
    By DavidP in forum Tech Board
    Replies: 2
    Last Post: 03-29-2004, 01:16 AM
  5. Success - Output to Printer
    By noraa in forum C Programming
    Replies: 5
    Last Post: 08-04-2002, 09:12 AM