Topic: cout.setf(0,ios_base::floatfield)


Author: jbarfurth@vossnet.de (Joerg Barfurth)
Date: 1999/12/08
Raw View
Dietmar Kuehl <dietmar.kuehl@claas-solutions.de> wrote:

> This example is wrong. It should be
>=20
>   std::cout.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield)=
;
>=20
> The important portion is the conversion to the type 'fmtflags' if it is
> necessary, ie. if an implementation choose to use a different type than
> 'int', eg. an enum (like eg. my implementation does).

There ways to do it without a type conversion, e.g.

std::cout.setf(~std::ios_base::floatfield, std::ios_base::floatfield);

-- J=F6rg Barfurth

BTW: I choose this particular form, because I can't make it work on
MSVC6 with enums.=20
Having
    enum E { E1 =3D 2 };
    E operator~(E) { /*...*/ };

    E e =3D ~E1;
the user-defined operator is not called=20
(sometimes it is diagnosed as ambiguous) :-(
---
[ 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: Benedikt Weber <weber@ibk.baum.ethz.ch>
Date: 1999/12/06
Raw View


In Stroustrup 3rd Ed. on page 628 there is the example:

       cout.setf (0,ios_base::floatfield)  //  reset cout to default

I have one compiler that does accept this and one that doesn't. The
declaration of setf in ios_base is:

       fmtflags setf (fmtflags fmtfl, fmtflags mask);

In one compiler, fmtflags is implemented as an  int, in the other as an
enum. According to the standard, both  are possible. However, the
example in Stroustrup  works only with the int implementation because an
int is not implicitely converted to an enum

Is the example really correct? How can I reset floatfield, if the form
given in the example is not correct?

Benedikt Weber

[ moderator's note: html attachment deleted. Please do not post
  html or any other attachments. Set your newsreader to post only
  plain text. -sdc ]



[ 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: "T.N" <txn131@psu.edu>
Date: 1999/12/07
Raw View
cout.setf (0, ios::floatfield)    ;    // see if your compiler accepts this

"Benedikt Weber" <weber@ibk.baum.ethz.ch> wrote in message
news:384BBA30.BA79A2F3@ibk.baum.ethz.ch...
>
>
>
> In Stroustrup 3rd Ed. on page 628 there is the example:
>
>        cout.setf (0,ios_base::floatfield)  //  reset cout to default
>
> I have one compiler that does accept this and one that doesn't. The
> declaration of setf in ios_base is:
>
>        fmtflags setf (fmtflags fmtfl, fmtflags mask);
>
> In one compiler, fmtflags is implemented as an  int, in the other as an
> enum. According to the standard, both  are possible. However, the
> example in Stroustrup  works only with the int implementation because an
> int is not implicitely converted to an enum
>
> Is the example really correct? How can I reset floatfield, if the form
> given in the example is not correct?
>
> Benedikt Weber
>
> [ moderator's note: html attachment deleted. Please do not post
>   html or any other attachments. Set your newsreader to post only
>   plain text. -sdc ]
>
>
>
> [ 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              ]
>
---
[ 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: Dietmar Kuehl <dietmar.kuehl@claas-solutions.de>
Date: 1999/12/07
Raw View
Hi,
In article <384BBA30.BA79A2F3@ibk.baum.ethz.ch>,
  Benedikt Weber <weber@ibk.baum.ethz.ch> wrote:
> In Stroustrup 3rd Ed. on page 628 there is the example:
>
>        cout.setf (0,ios_base::floatfield)  //  reset cout to default

This example is wrong. It should be

  std::cout.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield);

The important portion is the conversion to the type 'fmtflags' if it is
necessary, ie. if an implementation choose to use a different type than
'int', eg. an enum (like eg. my implementation does).
--
<mailto:dietmar.kuehl@claas-solutions.de>
homepage: <http://www.informatik.uni-konstanz.de/~kuehl>


Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: phalpern@newview.org (Pablo Halpern)
Date: 1999/12/07
Raw View
Benedikt Weber <weber@ibk.baum.ethz.ch> wrote:
>
>In Stroustrup 3rd Ed. on page 628 there is the example:
>
>       cout.setf (0,ios_base::floatfield)  //  reset cout to default
>
>I have one compiler that does accept this and one that doesn't. The
>declaration of setf in ios_base is:
>
>       fmtflags setf (fmtflags fmtfl, fmtflags mask);
>
>In one compiler, fmtflags is implemented as an  int, in the other as an
>enum. According to the standard, both  are possible. However, the
>example in Stroustrup  works only with the int implementation because an
>int is not implicitely converted to an enum
>
>Is the example really correct? How can I reset floatfield, if the form
>given in the example is not correct?

   cout.setf(ios_base::fmtflags(0), ios_base::floatfield);

---------------------------------------------------------------
Pablo Halpern                              phalpern@newview.org
Check out my new book, The C++ Standard Library from Scratch at
http://www.halpernwightsoftware.com/stdlib-scratch


[ 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              ]