Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing Problems using iostream

Posted on 2000-03-15
7
Medium Priority
?
262 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
[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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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++.

670 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