Solved

printing

Posted on 1998-08-19
10
210 Views
Last Modified: 2010-04-10
how do I print to the printer? do I use cout<< or fprintf, and can you show me how to use them, and do I have to declarethe printer I am using.  I am hook onto a network
Thanks fot your help!
0
Comment
Question by:lance100
  • 5
  • 5
10 Comments
 

Author Comment

by:lance100
Comment Utility
Edited text of question
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
Comment Utility
In standard C++ (not dealing directly with a particular OS, like windows) you deal with a printer as if it is a file.  Thus you print by outputing to a file with the appropriate name.

contineus
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
You need to open a file that cooresponds to a printer and then just write the information you would like to print.  There are lots of ways to open a file and write to it.  But the most convientient is likely to be using C++'s file streams.  Like

fstream Printer("LPT1",ios::out,filebuf::sh_none);

This opens a file called "LPT1".  The file is opened for output, but not input.   The file is opened without sharing (no one else can open it until you close it.)  

Then you can print to the file just like you ordinarily output to a stream.  Like

Printer << "This is a test" << endl;

You will ned to figure out the name of the file to open.  That depends on the operating system you are using, the network, and which printer you actually want.  If you can supply more details, I may be able to help you in that area.
0
 

Author Comment

by:lance100
Comment Utility
Thanks for the help.  I will try it now and let you now what happened
0
 

Author Comment

by:lance100
Comment Utility
the help you gave me didn't work.  I am trying to print this from Visual C++ V5.  I have to print out "The estimate total..... is: #" # is a number that I get from a variable got m_total.
hers is what I did:
fstream Printer("LPT1",ios::out,filebuf::sh_none);
Printer << "This estimate total... is:" << endl;
Printer<<m_total<<endl;

do you have to indentify the printer or is it that you can't print it out because I am using visual C. I am using a HP laserjet 6p on win 95, which I is connected with Novell . Please tell me how to print out such a simple statement.
Thank You
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Expert Comment

by:nietod
Comment Utility
As I said before, the real trick is to figure out the name of the file to be opened.  Use "LPT1" if the printer is connected to LPT1.  Use "COM1" if the printer is connected to COM1, etc  For a network, printer, there is a file name associated with the printer,  But what it is will depend on your network's set-up.  I can't tell you what it is.  However, you will have to specify a path to the file.  Thus if the file server is FS1, and the file is Q1, the file and path you specify would be "\\FS1\Q1"  But remember that you need to put two \'s in a string in order to specify a single \, thus you would type "\\\\FS1\\Q1" in your source code.
0
 

Author Comment

by:lance100
Comment Utility
can you tell me how to find the path to the printer.  I have tried going into the control panel and going into printers and I used the path it gave me but that did not work.
(\\\\ACS\\.hplaser6p.staff.acs) was what i used.  There was only \\ & \ so I added the extra slashes.
What did I do wrong or how do you fing the path?
Thanks
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
The slashes look right, but the file name might be wrong.  You've got three periods (".") in there which seems unlikely.  Are you sure that is name and path you saw in the printer set-up?

In my case, the printers seem to have to have names that follow the DOS 8.3 standard and there is no extension, so my file names are no more than 8 characters.  My paths are like

\\kepler\OkiLaser   => \\\\kepler\\OkiLaser
\\newton\IbmPro     => \\\\newton\\IbmPro
0
 

Author Comment

by:lance100
Comment Utility
If my code looks like this for printing a little report, how do I get the
field width to stay the same ever time I print it out.
eg. when I type in a company field like Microsoft then I type one in like
Cape Breton Regional Municipality, the whole report gets messed up because
of the different lengths. And if there is no company name in the space all
the outputs jam together. How can I fix this problem to have a consistent
report.
Thanks,

//////example of some of my variables declared above.
      m_custnum = _T("");
      m_ordernum = _T("");
      m_address = _T("");
      m_assigned = _T("");
      m_billcode = _T("");
      m_company = _T("");
      m_contact = _T("");
      m_contract = _T("");
      m_custponum = _T("");
      m_custref = _T("");



/////code to print out short report

fstream Printer("\\LPT1",ios::out,filebuf::sh_none);

      //output above strings

Printer<<"\rAlliance Computer Sytems / Atlantic Computer Services            SERVICE REPORT\n\r";
Printer<<"\r288 Welton Street   P.O. Box 1856     Phone 902 562-6600\n\r";
Printer<<"\rSydney, Nova Scotia B1P 6W4             Fax 902 562-6723\n\r\r";
Printer<<"\r _______________________________________________________________________________\n\r";
Printer<<"\r| Call Date: "<<m_calldate<<"  |  Status: "<<m_status<<"  |  Waiting for Parts: "<<m_waitparts<< " |  Order #: "<<m_ordernum<<"  |\n\r";      
Printer<<"\r|-------------------------------------------------------------------------------|\n\r";
Printer<<"\r| Customer #"<<m_custnum<<"                   | Customer Refernce #:"<<m_custref<<"|\n\r";
Printer<<"\r| Company: "<<m_company<<"           |      Customer P.O. #:"<<m_custponum<<"|\n\r";
Printer<<"\r| Address: "<<m_address<<"           |      Contract: "<<m_contract<<" |\n\r";
Printer<<"\r|                                              |\n\r";
Printer<<"\r|                                              |\n\r";              
Printer<<"\r|-------------------------------------------------------------------------------|\n\r";

      


      MessageBox("Your request is being Printed!");
      UpdateData(FALSE);


0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
You should get a reference on the C++ iostreams.  If you are using VC there is stuff in the on-line help.  Otherwise you need to get a book that describes using streams.  There are lots.)

But briefly, you can set the width of the item to be output next with the setw() manipulator  (There are dozens of other manipulators, that is why you need a good reference)  Like

Printer<<" Order #: "<< setw(10) << m_ordernum << endl;

The setw(10) will pad the m_ordernum to 10 characters (with leading spaces), it doesn't print although it looks like it should.  Also note that the endl manipulators is used to indicate the end of the line.  The "\r\n" shouldn't ussually be used in C++.  endl should be used because it should be device/data independant.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now