Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

Output Never Gets to Printer -- Why?

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

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.

	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.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date