Solved

how to set width for printing

Posted on 1998-08-21
2
269 Views
Last Modified: 2010-04-10
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);

0
Comment
Question by:lance100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1170885
I provided an answer on your other question, but here is some reference material to get you started.

ios

#include <iostream.h>

As the iostream class hierarchy diagram shows, ios is the base class for all the input/output stream classes. While ios is not technically an abstract base class, you will not usually construct ios objects, nor will you derive classes directly from ios. Instead, you will use the derived classes istream and ostream or other derived classes.

Even though you will not use ios directly, you will be using many of the inherited member functions and data members described here. Remember that these inherited member function descriptions are not duplicated for derived classes.

Data Members (static) — Public Members

basefield   Mask for obtaining the conversion base flags (dec, oct, or hex).

adjustfield   Mask for obtaining the field padding flags (left, right, or internal).

floatfield   Mask for obtaining the numeric format (scientific or fixed).

Construction/Destruction — Public Members

ios   Constructor for use in derived classes.

~ios   Virtual destructor.

Flag and Format Access Functions — Public Members

flags   Sets or reads the stream's format flags.

setf   Manipulates the stream's format flags.

unsetf   Clears the stream's format flags.

fill   Sets or reads the stream's fill character.

precision   Sets or reads the stream's floating-point format display precision.

width   Sets or reads the stream's output field width.

Status-Testing Functions — Public Members

good   Indicates good stream status.

bad   Indicates a serious I/O error.

eof   Indicates end of file.

fail   Indicates a serious I/O error or a possibly recoverable I/O formatting error.

rdstate   Returns the stream's error flags.

clear   Sets or clears the stream's error flags.

User-Defined Format Flags — Public Members

bitalloc   Provides a mask for an unused format bit in the stream's private flags variable (static function).

xalloc   Provides an index to an unused word in an array reserved for special-purpose stream state variables (static function).

iword   Converts the index provided by xalloc to a reference (valid only until the next xalloc).

pword   Converts the index provided by xalloc to a pointer (valid only until the next xalloc).

Other Functions — Public Members

delbuf   Controls the connection of streambuf deletion with ios destruction.

rdbuf   Gets the stream's streambuf object.

sync_with_stdio   Synchronizes the predefined objects cin, cout, cerr, and clog with the standard I/O system.

tie   Ties a specified ostream to this stream.

Operators — Public Members

operator void*   Converts a stream to a pointer that can be used only for error checking.

operator !   Returns a nonzero value if a stream I/O error occurs.

ios Manipulators

dec   Causes the interpretation of subsequent fields in decimal format (the default mode).

hex   Causes the interpretation of subsequent fields in hexadecimal format.

oct   Causes the interpretation of subsequent fields in octal format.

binary   Sets the stream's mode to binary (stream must have an associated filebuf buffer).

text   Sets the stream's mode to text, the default mode (stream must have an associated filebuf buffer).

Parameterized Manipulators

(#include <iomanip.h> required)

setiosflags   Sets the stream's format flags.

resetiosflags   Resets the stream's format flags.

setfill   Sets the stream's fill character.

setprecision   Sets the stream's floating-point display precision.

setw   Sets the stream's field width (for the next field only).

Abstract Stream Base Class

See Also   istream, ostream
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170886
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Move constructor only called if marked noexcept? 6 114
IdTCPClient1->Disconnect(); not working 3 87
FMX TCameraComponent Problem 2 93
How do i run a c++ file? 15 52
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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