Solved

Printing from Borland C++

Posted on 1998-09-15
8
422 Views
Last Modified: 2008-03-17
I have a program written in Borland C++ version 4, and want a function that will send the data in the DOS window straight to the printer.
Any ideas
0
Comment
Question by:andy10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1172763
I don't know how to print the information that is in the DOS window, but I do know how to print from a DOS application, if that is what you want.
0
 

Author Comment

by:andy10
ID: 1172764
I'm not really sure. I wrote a program using Linux, and have run it through Borland C++ to make an executable file. When the program runs, it runs in a basic window, and I was wondering if there was any function that could send this data to the printer.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172765
If you just want all of the output of the program to go to a printer, you can redirect it using >> on the command line, like

SomeExe paramater1 parameter2 >> lpt1

will send the output to lpt1.  You can use "prn" for the default printer port, lptX (where x is a number) for the parallel ports and comX for the serial ports.

If you want the program to actually print out to a printer, that is different.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:andy10
ID: 1172766
I would like the program to send the output to the printer, instead of to the monitor. Is this possible? I thought there was maybe just a line of code that could do this?
cheers
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172767
The above technique will do that.  But it is the user's responsibility to do it.  That is, they must add ">> lpt1" to the end of the command to make it print to the printer instead of the screen.

(note if the printer is a laser or ink jet printer the final page might not print, unless the program outputs a formfeed, or the user presses the printer's eject button.)

If you want to change the program so it always goes to the printer (and you won't have problems with the last page).  You can do so retty easily.  What you need to do will depend on how it currently prints.  Like does it currently display to "cout"? or does it use "printf()"?
0
 

Author Comment

by:andy10
ID: 1172768
yeah, I'd like to change the program so that it always prints to the printer. It currently prints using - cout.
thanks
0
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 1172769
In that case, the general approach is to output to a file stream, rather than to cout  (you can probably just do a search and replace to make this change).  

First create a file stream object (it may have to be global since cout was global, but you may be able to make it local to a procedure depending on your program).  have the stream object open up the printer port for writing, like

fstream OutPut(":LPT1",iou:out);

note.  I can't remember if you want the ":" before the lpt1 or not.  try it both ways.  You may need to adjust this if you printer is not on lpt, let me know if you have problems.

Then just replace every occurance of "cout" with the new stream, "OutPut".

At the end of the program, you may want to print a form feed.  This is nce for dot matix printers and is necessary for page printers (like laser printers).  Just print the form feed using

OutPut << '\f';

let me know if you have questions.
0
 

Author Comment

by:andy10
ID: 1172770
cheers, i'll give that a try
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question