Solved

Printing Problems using iostream

Posted on 2000-03-15
7
251 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Travis12345
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
: )
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

763 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

7 Experts available now in Live!

Get 1:1 Help Now