Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using printer from C++ Console App 1

Status
Not open for further replies.

benlinkknilneb

Programmer
May 16, 2002
590
US
I'm writing a small C++ app that I would like to connect to my printer. Everywhere I've ever looked showed the use of
Code:
#include<fstream.h>

int main()
{
   ofstream printer(&quot;LPT1&quot;);
   printer<<&quot;This text should appear on the printer&quot;<<endl;
   return 0;
}

but when i did this, i got nothing. No errors, no warnings, nothing printed out. The computer appeared to open LPT1 successfully, but nothing came out. I double-checked, and that IS the port my printer is on... so I'm at a loss. Can anyone show me another simple way? I don't want to go through the MFC device contexts and stuff.

Ben
 
try this:

#include<windows.h>
int main()
{
ShellExecute(NULL,&quot;print&quot;,&quot;path_to_file&quot;,NULL,NULL,SW_SHOWNORMAL);
return 0;
}

replace path_to_file with the file that contain the text that you want to print.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top