Solved

Printing text to a printer - need example

Posted on 2006-11-14
2
172 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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. …
  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 …
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

747 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

7 Experts available now in Live!

Get 1:1 Help Now