Topic: strange behavior of setw and standard strings.


Author: "Roger Orr" <rogero@howzatt.demon.co.uk>
Date: Thu, 13 Dec 2001 00:14:25 GMT
Raw View
I searched google groups for "gcc setw bug" and found a reference

"52382 [fixed with libstdc++-v3] setw is ignored for strings output
Bug#52382: setw is ignored for strings output"

gcc 2.95.3-4 [on Windows] does work as expected.

so it looks like it is a known gcc bug which has been fixed in the latest
release(s).

Perhaps there is a later version for the platforms you mention?

Interestingly, or not, VC 5 has the same bug but it was fixed by VC 6.

I suspect any further postings on this topic should be directed to the
compiler-specific newsgroups.

Regards,
Roger Orr.
--
MVP in C++ at www.brainbench.com


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: jpotter@falcon.lhup.edu (John Potter)
Date: Thu, 13 Dec 2001 02:25:08 GMT
Raw View
On Thu, 13 Dec 2001 00:14:25 GMT, "Roger Orr"
<rogero@howzatt.demon.co.uk> wrote:

> I suspect any further postings on this topic should be directed to the
> compiler-specific newsgroups.

It may be worth noting that setw for strings was overlooked until late
in the standard process.  The compilers that do not support it are
just marching to an older draft standard.

John

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Roger Orr" <rogero@howzatt.demon.co.uk>
Date: Sun, 9 Dec 2001 19:15:33 GMT
Raw View
Thierry De Corte wrote in message ...
>Hi all,
>
>    From my understanding of the standard, the manipulator setw() should
>work with both C and C++ style strings. But from my experimentation, setw()
>works with C strings but DOESN'T works with C++ style strings.
>
>For example:
>
>string my_str("foo");
>cout.setf(ios::left, ios::adjustfield);
>cout << setw(10) << my_str << "**" << "++";
>
>I get the following unexpected result (the setw was applied to the "**"
>string instead of the foo string):
>
>foo**        ++


You should get "foo       **++" on a standards comforming compiler.
In particular 21.3.7.9p4 explicitly states width(0) will be called after
streaming a string.

Out of interest, what compiler are you using?

Roger Orr
--
MVP in C++ at www.brainbench.com



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Thierry De Corte" <tdecorte@wavesat.com>
Date: Tue, 11 Dec 2001 16:00:43 GMT
Raw View
I can reproduce the problem with GNU gcc (g++) on Linux and VxWorks
plateform.

After testing on more compilers, I found out that the behavior is correct
(no bug) on VisualC++ and Borland compiler for Windoze.

"Roger Orr" <rogero@howzatt.demon.co.uk> wrote in message
news:1007857800.21612.0.nnrp-01.9e98aa01@news.demon.co.uk...
>
> Thierry De Corte wrote in message ...
> >Hi all,
> >
> >    From my understanding of the standard, the manipulator setw() should
> >work with both C and C++ style strings. But from my experimentation,
setw()
> >works with C strings but DOESN'T works with C++ style strings.
> >
> >For example:
> >
> >string my_str("foo");
> >cout.setf(ios::left, ios::adjustfield);
> >cout << setw(10) << my_str << "**" << "++";
> >
> >I get the following unexpected result (the setw was applied to the "**"
> >string instead of the foo string):
> >
> >foo**        ++
>
>
> You should get "foo       **++" on a standards comforming compiler.
> In particular 21.3.7.9p4 explicitly states width(0) will be called after
> streaming a string.
>
> Out of interest, what compiler are you using?
>
> Roger Orr
> --
> MVP in C++ at www.brainbench.com
>
>
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Thierry De Corte" <tdecorte@wavesat.com>
Date: Tue, 4 Dec 2001 18:47:07 GMT
Raw View
Hi all,

    From my understanding of the standard, the manipulator setw() should
work with both C and C++ style strings. But from my experimentation, setw()
works with C strings but DOESN'T works with C++ style strings.

For example:

string my_str("foo");
cout.setf(ios::left, ios::adjustfield);
cout << setw(10) << my_str << "**" << "++";

I get the following unexpected result (the setw was applied to the "**"
string instead of the foo string):

foo**        ++

If you try with C string:
char my_str[4] = {'f', 'o', 'o', '\0'};
cout.setf(ios::left, ios::adjustfiled);
cout << setw(10) << my_str << "**" << "++";

The result is (I was expecting this result):
foo       **++

It demonstrate that streaming a C++ string doesn't take into account the
setw() and doesn't reset the width value to 0 after streaming (like any
basic types).

Is this the expected behavior? If yes, it's a major drawback in using the
string class...



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]