Solved

Printing Problems using iostream

Posted on 2000-03-15
7
254 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now