From: Karl Nelson (kenelson_at_[hidden])
Date: 2002-02-01 12:08:20
> > The problem is you just interpreted "width" to mean "maximum width".
> > But in this context it means "minumum width". As it does in iostream
> > as well. In fact, iostream would completely ignore width for
> > the above specifier.
> Yes and no. When I said a "user-defined type could wreak havoc on
> formatting," I was thinking, in part, in terms of maximum width. I think
> there's a place for that. However, I do realize that width for both
> printf() and IOStreams is minimum, and there's good reason for that: you
> don't accidentally lose valuable information.
> Still, "0x16+0x17i" is only 10 characters, so output B is what I would
> expect to be the result.
So how would you then specify you want A? Ie. If printing
a matrix class and you want every number in the matrix printed
> > Thus either A or B would have been better.
> Since your width was only five, you never got to see any padding with the
> complex<> output. cout was using setw(5) as indicating a minimum width, but
> the result was always at least five characters.
Quite right. My fault.
> > This is a big lump in printf formating (which we should not replicate)
> > which is the width field means generate no less than. According to that
> > rule I would guess output A. It generated no less than 10 chars for
> > each int conversion.
> That's not such a problem as you suggest. If printf() (and IOStreams) were
> to treat that as a maximum width, then the output would be truncated without
> any indication. They err on the side of showing all important information
> at the cost of mucking with any formatting you may have desired.
> > Second point, is that unlike fortran C++ does not have a cap limit
> > when you hit the maximum. Ie. should format("%.4d" , 12345) print
> > 1234, 2345, or ####?
> Displaying some placeholder characters in lieu of output when a maximum
> width specification is exceeded is reasonable. However, the default should
> be a minimum width approach; the format string should have to invoke the
> maximum width behavior explicitly. So, in IOStreams, there should be a
> setmaxw() manipulator with corresponding mfs and state information. There
> should also be a locale-controlled fill character to indicate data that
> would have displayed were it not wider than the allotted field width.
That would be a good idea.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk