Solved

printing

Posted on 1998-08-19
10
212 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
ID: 1170693
Edited text of question
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1170694
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
ID: 1170695
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
ID: 1170696
Thanks for the help.  I will try it now and let you now what happened
0
 

Author Comment

by:lance100
ID: 1170697
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 1170698
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
ID: 1170699
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
ID: 1170700
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
ID: 1170701
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
ID: 1170702
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

912 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

16 Experts available now in Live!

Get 1:1 Help Now