Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Mar 27, 1997

Output Never Gets to Printer -- Why?

Question:
When I run the following program:
#include 
main()
{
fstream printer1;
printer1.open("prn", ios::out);
printer1 << "Hello World";
}
the output never makes it to the printer. What am I doing wrong?

Answer:
When it comes to external devices like printers, etc., there could be a dozen problems that prevent it from printing.

Assuming that on your platform there is a predefined file called "prn" that will cause output to your printer, assuming that is true and also assuming that your printer is connected correctly and configured well, the only reason I can think of is that the stream implementation is buffered and requires an explicit flush to work (see example below).

Also, make sure that the program is not creating a file under the current directory named "prn"; if this is so, your platform does not treat the filename "prn" in any special way.

#include 
main()
{
	fstream printer1;
	printer1.open("prn", ios::out);
	printer1 << "Hello World" << flush;
}
Hope that helps.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date