Topic: <string> == real standard type


Author: ark@research.att.com (Andrew Koenig)
Date: 1998/07/10
Raw View
In article <6o0jsh$5k1$1@shell7.ba.best.com>,
Nathan Myers <ncm@nospam.cantrip.org> wrote:

> Michel Michaud<Michel.Michaud@sympatico.ca> wrote:
> >What should be output by :
> >    {
> >    string text("Hello");
> >    cout << '[' << setw(10) << right << text << ']';
> >    }

> >Shouldn't it be [     Hello] ?

> Yes.

g++ 2.8 gets it wrong too.  Sigh.
--
    --Andrew Koenig
      ark@research.att.com
      http://www.research.att.com/info/ark



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Michel Michaud" <Michel.Michaud@sympatico.ca>
Date: 1998/07/08
Raw View
I have just a simple question, with, I hope, a simple answer.

What should be output by :

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
    {
    string text("Hello");

    cout << '[' << setw(10) << right << text << ']';
    }

Shouldn't it be [     Hello] ?

Mr Plauger implementation in VC 5, doesn't care about anything and
you get [Hello]...

Neither Stroustrup nor Lippman give any exemple with manipulators and
strings, and the standard could be interpreted in both ways I think.

It's very easy to patch, but I need to know if we are supposed to
say :
    cout << '[' << setw(10) << right << text.c_str() << ']';

that is a very ugly solution that makes me think that the perpetual
quest for a good string type is not over yet.

Michel Michaud, micm19@mail2.cstjean.qc.ca



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/07/08
Raw View
Michel Michaud<Michel.Michaud@sympatico.ca> wrote:
>What should be output by :
>    {
>    string text("Hello");
>    cout << '[' << setw(10) << right << text << ']';
>    }
>
>Shouldn't it be [     Hello] ?

Yes.

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "P.J. Plauger" <pjp@dinkumware.com>
Date: 1998/07/09
Raw View
Michel Michaud <Michel.Michaud@sympatico.ca> wrote in article <FJNo1.7$x51.87002@news21.bellglobal.com>...
> I have just a simple question, with, I hope, a simple answer.

The question is simple, but the answer isn't.

> What should be output by :
>
> #include <iostream>
> #include <iomanip>
> #include <string>
> using namespace std;
>
> int main()
>     {
>     string text("Hello");
>
>     cout << '[' << setw(10) << right << text << ']';
>     }
>
> Shouldn't it be [     Hello] ?

It should now. It wasn't required at the time VC++ V5.0 froze. The version
that pads is percolating out to the field as our customers ship new
releases.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: jkanze@otelo.ibmmail.com
Date: 1998/07/09
Raw View
In article <6o0jsh$5k1$1@shell7.ba.best.com>,
  ncm@nospam.cantrip.org (Nathan Myers) wrote:
> Michel Michaud<Michel.Michaud@sympatico.ca> wrote:
> >What should be output by :
> >    {
> >    string text("Hello");
> >    cout << '[' << setw(10) << right << text << ']';
> >    }
> >
> >Shouldn't it be [     Hello] ?
>
> Yes.

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
what soever. Your implementation may have been written to conform to
an earlier version.

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
        +49 (0)69 66 45 33 10    mailto: jkanze@otelo.ibmmail.com
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient=E9e objet --
              -- Beratung in objektorientierter Datenverarbeitung

-----=3D=3D Posted via Deja News, The Leader in Internet Discussion =3D=3D=
-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]