?
Solved

Printing text to a printer - need example

Posted on 2006-11-14
2
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 750 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 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.
Suggested Courses

762 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