Link to home
Start Free TrialLog in
Avatar of lance100
lance100

asked on

how to set width for printing

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 ouyputs 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);

ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

note in particular the manipulators listed at the end.  the "ios manipulators" don't take parameters, like

cout << oct << 123;

causes 123 to print in octal.

The "parameterized manipulators"  take parameters, like

cout << setf('*') << setw(20) << 123;

causes 123 to be padded with *'s on the left to a width of 20.