|
From: Michael C. <jd...@ho...> - 2001-09-12 07:44:37
|
Hi, I have little to no experience in windows programming so I searched the web and found a Borlands site that has an example of how it does it. url: http://www.totse.com/en/computers/c_cplusplus_programming_how_to/iostream.html Hope this helps, Michael >From: "Ian Weston" <lak...@ho...> >Reply-To: dev...@li... >To: dev...@li... >Subject: [Dev-C++] Printing >Date: Tue, 11 Sep 2001 20:20:01 +0000 > >hello everyone. im writing a program in c++ and i need to be able to print >out text to a printer. i was just wondering if anyone knows how to do this. > >thankyou. ian. > >_________________________________________________________________ >Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp > > >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp |
|
From: CARLSON, J. M. <CA...@st...> - 2003-06-10 03:58:26
|
After doing many hours of web surfing. I found the best option for printing (from a console) is to write everything to a file, then open the file under notepad, or wordpad and print from there. I guess the reason is GUI's are so popular (ie Windows), printers need drivers and most are only supplied with window drivers now, (and linux if your lucky!) It may be possible to redirect the entire file output to the printer from dos using something like "c:\filename.exe >> lpt1" or something like that. If anyone has the exact details that would be great. I also found some information on using inp outp or inport outport for communicating through various ports. In this way the printer might be fed some data. But there are just too many unknowns for me to take a stab at. Jay |
|
From: Abhijit S. <mu...@gm...> - 2003-06-10 04:10:41
|
> It may be possible to
> redirect the entire file output to the printer from dos using something
like
> "c:\filename.exe >> lpt1" or something like that.
Actually, that's `prn' in DOS. You can print directly by opening a file
using prn as the name. For example:
ofstream prn("prn");
if(!prn)
{
clog << "Printer not found" << endl;
}
else
{
// Print
prn.close();
}
Or in C, use fopen(), fprintf(), etc.
HTH.
________________________________________
Abhijit Shylanath
http://mudeth.tripod.com/
|
|
From: Per W. <pw...@ia...> - 2003-06-10 10:26:02
|
It is possible to open lpt1 or prn as a file also. However, depending on what os, driver, printer you have, you might have to fiddle iin the printer settings to make sure that the printer is avavailable in console windows too. Some combinations of OS and printer drivers might not even support text output from a console. /Per W On Mon, 9 Jun 2003, CARLSON, JAY MM1 wrote: > After doing many hours of web surfing. I found the best option for printing > (from a console) is to write everything to a file, then open the file under > notepad, or wordpad and print from there. I guess the reason is GUI's are > so popular (ie Windows), printers need drivers and most are only supplied > with window drivers now, (and linux if your lucky!) It may be possible to > redirect the entire file output to the printer from dos using something like > "c:\filename.exe >> lpt1" or something like that. If anyone has the exact > details that would be great. I also found some information on using inp > outp or inport outport for communicating through various ports. In this way > the printer might be fed some data. But there are just too many unknowns > for me to take a stab at. > > Jay > > > ------------------------------------------------------- > This SF.net email is sponsored by: Etnus, makers of TotalView, The best > thread debugger on the planet. Designed with thread debugging features > you've never dreamed of, try TotalView 6 free at www.etnus.com. > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: CARLSON, J. M. <CA...@st...> - 2003-06-10 04:37:43
|
Reply to printing - take 2 - This is a good way to print from a console. A
file could be created a console program and then printed with a system()
call. Below is a sample program that demonstrates how it works. It is
longer than it has to be to show several variations at the same time.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void) {
// assuming c:\test.txt exits, this will work.
// c:\test.txt should be a small file because it will print 4 times.
// Notice the double backslash in the first non comment line
// The backslash is a control characher so the first one
// is stripped out before the command is executed.
system("print c:\\test.txt");
system("PRINT c:\\test.txt");
system("print C:\\TEST.TXT");
// Other ways to do the same thing.
// This line could be dangerous - unterminated string
const char* command01 = "Print C:\\test.txt"; /* do I need \0 ?
*/
const char* command02 = "Print C:\\test.txt\0"; /* \0 ends the string
*/
// This line could be dangerous - unterminated string
const char command03[] = "Print C:\\test.txt"; /* do I need \0 ?
*/
const char command04[] = "Print C:\\test.txt\0"; /* \0 ends the string
*/
system(command01);
system(command02);
system(command03);
system(command04);
// all valid dos commands can by used by system()
// you can get a list of commands by typing
// HELP + [enter key] (if installed)
//
system("PAUSE");
// notice case is not important to the system() call
return 0;
}
Jay
|
|
From: Per W. <pw...@ia...> - 2003-06-10 10:32:55
|
The compiler always zero-terminate strings if you just give it a chance.
char mystr[] = "foobar";
will store six characters and a termination. It's whey you try
char mystr[6] = "foobar";
that you might get into problems, since the array doesn't allocate space
for a termination. A lot of compilers will complain.
/Per W
On Mon, 9 Jun 2003, CARLSON, JAY MM1 wrote:
> Reply to printing - take 2 - This is a good way to print from a console. A
> file could be created a console program and then printed with a system()
> call. Below is a sample program that demonstrates how it works. It is
> longer than it has to be to show several variations at the same time.
>
> #include <iostream>
> #include <stdlib.h>
>
> using namespace std;
>
> int main(void) {
>
> // assuming c:\test.txt exits, this will work.
> // c:\test.txt should be a small file because it will print 4 times.
> // Notice the double backslash in the first non comment line
> // The backslash is a control characher so the first one
> // is stripped out before the command is executed.
> system("print c:\\test.txt");
> system("PRINT c:\\test.txt");
> system("print C:\\TEST.TXT");
>
> // Other ways to do the same thing.
> // This line could be dangerous - unterminated string
> const char* command01 = "Print C:\\test.txt"; /* do I need \0 ?
> */
> const char* command02 = "Print C:\\test.txt\0"; /* \0 ends the string
> */
> // This line could be dangerous - unterminated string
> const char command03[] = "Print C:\\test.txt"; /* do I need \0 ?
> */
> const char command04[] = "Print C:\\test.txt\0"; /* \0 ends the string
> */
>
> system(command01);
> system(command02);
> system(command03);
> system(command04);
>
>
> // all valid dos commands can by used by system()
> // you can get a list of commands by typing
> // HELP + [enter key] (if installed)
> //
> system("PAUSE");
> // notice case is not important to the system() call
> return 0;
> }
>
> Jay
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The best
> thread debugger on the planet. Designed with thread debugging features
> you've never dreamed of, try TotalView 6 free at www.etnus.com.
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|