Solved

Printing text to a printer - need example

Posted on 2006-11-14
2
178 Views
Last Modified: 2010-04-01
I am new to C++ and I need some help.
I need to know how to print text to a printer in a cosole application.

I can print to the screen but I can't rint to the printer.

Thanks!
0
Comment
Question by:koneill99
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 17939592
You can write to the printer using an ofstream with 'PRN' as the filename, e.g.

#include <fstream>
using namespace std;

void test_printer() {

ofstream printer("PRN");

printes << "This is a test" << endl;

}
0
 
LVL 6

Accepted Solution

by:
_iskywalker_ earned 250 total points
ID: 17940570
you could also generate a text, save it as txt file then call:
char filename[]="my.txt";
char command[256];
sprintf(command,"a2ps %s -o my.ps",filename);
system(command);
sprintf(command," lpr my.ps");
system(command);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.

932 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

13 Experts available now in Live!

Get 1:1 Help Now