Solved

Printing Problems using iostream

Posted on 2000-03-15
7
259 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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++.

828 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