Solved

Printing text to a printer - need example

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 147
C++ to C# code conversion issue 4 108
Exception thrown at 0x00007FFD5BC81F28 7 44
show out valin of json for debugging in visaul c++ 1 33
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

823 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