how to print.

E

ego

ok! when I want to put the message "abc" to the screen I use the
methode cout<<"abc";
but what can I do if want to print that directly to the printer?
 
A

Alexander

Quite complicated. Probably platform dependent. Google "printer
library". You should choose a platform though (windows, linux, etc.)
 
J

Juha Nieminen

ego said:
ok! when I want to put the message "abc" to the screen I use the
methode cout<<"abc";
but what can I do if want to print that directly to the printer?

This is something which is basically impossible to do in a portable
way, which is why the C++ standard does not include any such thing.

You'll have to consult the API documentation of your operating system
to see how it's done there.
 
J

Juha Nieminen

Sherm Pendley said:
Needlessly so on both counts, IMHO - printing to paper is a common task
that should have been standardized and simplified *ages* ago. But so
it goes... :-(

Printing *what* on paper? Text? Using which font? Is it a font supported
by the printer itself, by the operating system, or a program's own font?
In what format would the font be? TTF?

Of course text is not the only thing that one may want to print. Bitmap
images are one obvious thing to print, but you also want to print vector
graphics (probably the second most common thing to print after text).
What types of vector graphics primitives should the standard support for
this purpose? And that's not to talk about dash patterns, fill patterns,
transformations, and whatnot.

You know, maybe it's *better* that the C++ standard doesn't go that
path.
 
K

Kai-Uwe Bux

Juha said:
Printing *what* on paper? Text?

Well,

std::cprt << "message\n";

should print a C-string,

std::cprt << std::string( "message\n" );

should print a std::string, and

std::cprt << 10;

should print an int -- obviously :)
Using which font? Is it a font supported
by the printer itself, by the operating system, or a program's own font?
In what format would the font be? TTF?

That, of course, would be dependent on the implementation in the same way as
it is currently with std::cout.

Of course text is not the only thing that one may want to print. Bitmap
images are one obvious thing to print, but you also want to print vector
graphics (probably the second most common thing to print after text).
What types of vector graphics primitives should the standard support for
this purpose? And that's not to talk about dash patterns, fill patterns,
transformations, and whatnot.

Yeah, and in the same way one might want to put those on the screen.
However, that one could have legitimate needs that cannot be satisfied by
std::cout is not an argument against providing std::cout or even having it
in the standard. In the same way, I fail to grasp why the above should
constitue an argument against std::cprt.
You know, maybe it's *better* that the C++ standard doesn't go that
path.

Maybe, but maybe not. I wonder what would be valid reasons one way or the
other.


Best

Kai-Uwe Bux
 
A

Alf P. Steinbach /Usenet

* ego, on 04.08.2010 19:38:
ok! when I want to put the message "abc" to the screen I use the
methode cout<<"abc";
but what can I do if want to print that directly to the printer?

Depends on the printer.

But in Windows you can redirect the output to the 'prn' device,

C:\> myprog >prn

and possibly your printer will print something! ;-)

Wait, wait, you may have to use the 'print' command first, to set up 'prn'.

A simple method in Windows is

C:\> myprog >result.txt

C:\> notepad /p result.txt

Disclaimer: this is off my hindbrain, it's at least a decade since I've needed
this so details may not be totally correct.

Similarly, in *nix you have lp* programs you can pipe the output to.

Disclaimer: it's about three decades since I implemented those programs (in C),
a "Mosaic spooling system" as I recall, and never used since then...


Cheers & hth.,

- Alf
 
D

Default User

Sherm Pendley said:
Needlessly so on both counts, IMHO - printing to paper is a common task
that should have been standardized and simplified *ages* ago. But so
it goes... :-(

Way back in ancient days, Turbo C++ had stdprn and cprn extensions for
sending to the printer when in DOS mode.




Brian
 
I

Ian Collins

ok! when I want to put the message "abc" to the screen I use the
methode cout<<"abc";
but what can I do if want to print that directly to the printer?

system( <whatever command send the file to a printer> );
 
J

James Kanze

std::cprt << "message\n";
should print a C-string,
std::cprt << std::string( "message\n" );
should print a std::string, and
std::cprt << 10;
should print an int -- obviously :)
That, of course, would be dependent on the implementation in
the same way as it is currently with std::cout.

It's even dependent on the implementation where std::cout
outputs to. I could be the printer. (I've certainly seen the
case where it did.)

Of course, on most modern systems, the printer isn't accessible
from a user program. The most you can do is output to a file,
and then somehow arrange for that file to be read by the program
which manages the printer. (Under Unix, you can also arrange
for the output to be piped to the program which manages the
printer.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top