Title
Setw useless for strings
Status
dup
Section
[string.io]
Submitter
Steve Clamage

Created on 1998-07-09.00:00:00 last changed 172 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

Duplicate: 25

Date: 1998-07-09.00:00:00

In a comp.std.c++ posting Michel Michaud wrote: What should be output by:

   string text("Hello");
   cout << '[' << setw(10) << right << text << ']';

Shouldn't it be:

   [     Hello]

Another person replied: Actually, according to the FDIS, the width of the field should be the minimum of width and the length of the string, so the output shouldn't have any padding. I think that this is a typo, however, and that what is wanted is the maximum of the two. (As written, setw is useless for strings. If that had been the intent, one wouldn't expect them to have mentioned using its value.)

It's worth pointing out that this is a recent correction anyway; IIRC, earlier versions of the draft forgot to mention formatting parameters whatsoever.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg155
1998-07-09 00:00:00admincreate