how to save or print

This is a discussion on how to save or print within the C++ Programming forums, part of the General Programming Boards category; i have a program that works out the net pay of and employee and the tax and other payments. it ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    1

    how to save or print

    i have a program that works out the net pay of and employee and the tax and other payments. it shows the outputs on the screen after calculation and i would like to give the option to either save, exit or print has anyone any suggestions??

    attached is my code. password 150284.
    astrix code would be apreciated also.
    Attached Files Attached Files

  2. #2
    Unregistered
    Guest
    to save to a file you will need to use ofstream or fstream or FILE *, and to read information back into a program again (or else why save it to begin with?) use ifstream or fstream or FILE *.

    To print to a printer you can use LPT1 as a file name if the printer is on that port and you are using a DOS program.

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    It is a good thing I keep this handy... this question comes up every week.

    Code:
    #include <iostream>
    #include <fstream>
    #include <stdlib>
    using namespace std ;
    
    int main()
    {
    
            char printer[10] = "LPT1:";
            char character;
    
            
            ofstream prnt (printer);
    
    
            if (prnt.fail()) 
            {
                    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-09-2008, 07:27 AM
  2. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 07:26 PM
  3. Replies: 1
    Last Post: 07-31-2002, 11:35 AM
  4. send data to printer and print on paper
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 07-22-2002, 05:19 AM
  5. How to print out the data throw printer.Attn Salem
    By Jason in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 05:58 AM

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