Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printing Problems using iostream

Posted on 2000-03-15
7
Medium Priority
?
263 Views
Last Modified: 2010-04-10
I was curious on how to print something while using an iostream.  The program is DOS based and I want to print to be able to print output from the program on a printer instead of on the monitor.  Help Please
0
Comment
Question by:Travis12345
  • 3
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:Pacman
ID: 2620821
open file "prn" and write to it.
example:

FILE *fp = fopen("prn", "wb");

fprintf(fp, "Hello world,\r\n");
fprintf(fp, "this is my text on the printer!!!\r\n\n\n");

fclose(fp);


Is this what you want ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2620878
Right idea but the C++ way woudl be to use an file stream object, like

fstream Printer("LPT1",ios_base::out);

Printer << "This is a test" ;

Printer.close();

You can ouput "\r\n" to go to the next line and "\f" to go to the next page.  And on a page printer (laser, inkjet etc) you need to output a "\f" at the end to make the final page print.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2620895
The name of the file you want to print to is "prn", for the default printer or com1, com2, com3... for serial printer, or lpt1, lpt2, lpt3... for parallel printers.
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:Travis12345
ID: 2628956
I think Nietod is closest to what I need but it still didn't work.  I can send a copy of the source code to anyone who wants to work with it.
0
 
LVL 22

Accepted Solution

by:
nietod earned 800 total points
ID: 2629100
basically that is the C++ (instead of C) version of Packman's idea.

The code you sent me looks okay, but you don't print a a form feed at the end.  if the printer is a "page" pritner (one that prints to cut sheet pages, like a laser or ink jet printer) then you need to print a form feed at the end of each page--including the last page to be printed.   You print a form feed using "\f"  like

Printer << "\f";
0
 

Author Comment

by:Travis12345
ID: 2653501
I still can't get it to work but it's alright because my Computer Science teacher doesn't care.
0
 
LVL 9

Expert Comment

by:Pacman
ID: 2653732
: )
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

824 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