Topic: operator>>( bool& )


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 8 Feb 1995 16:41:46 GMT
Raw View
In article 792173375@graceland.att.com, pjl@graceland.att.com (Paul J. Lucas) writes:
> Now that bool is a built-in type, is the above defined in the
> streams library?
>
> If so, what are its semantics?  Does it try to parse the stream
> of characters like:
>
>  false: 0,f,F,false,False,fAlSe, ...
>  true: 1,t,T,true,True,tRuE, ...

I can tell you what it says in the Sept 94 draft, but I don't know whether
anything will change.

There is a new ios formatting flag, ios::boolalpha. If set, bool insertions and
extractions use locale-specific strings for true and false. The default
locale strings are "true" and "false".

The bool extractor then behaves this way:

 istream& operator>>(bool& b)
 {
  if( flags() & ios::boolalpha )
   ... extract locale-specific string
  else {
   int x = -1; // maybe "short int x;", the draft is inconsistent
   *this >> x; // attempt to extract a signed integer
   if( x == 0 ) b = false;
   else if( x == 1 ) b = true;
   else ... indicate failure
  }
  return *this;
 }
---
Steve Clamage, stephen.clamage@eng.sun.com






Author: admin@rzaix13.uni-hamburg.de (Bernd Eggink)
Date: 9 Feb 1995 10:24:06 GMT
Raw View
Paul J. Lucas (pjl@graceland.att.com) wrote:
>   Now that bool is a built-in type, is the above defined in the
>   streams library?

>   If so, what are its semantics?  Does it try to parse the stream
>   of characters like:

>    false: 0,f,F,false,False,fAlSe, ...
>    true: 1,t,T,true,True,tRuE, ...
>
>   Thanks.
>  --
>   - Paul J. Lucas   #ifndef COMMON_KNOWLEDGE
>     AT&T Bell Laboratories #include <stddisclaimer.h>
>     Naperville, IL  #endif

Default is 0 for false, 1 for true.

If the format flag basic_ios::boolalpha is set, an alphabetic format is
used, which depends on the current locale. For the default locale,
the strings are "false" and "true". As far as I can see from the WP,
only lower case letters are accepted.

--
+----------------------------------+
|          Bernd Eggink            |
|    Rechenzentrum Uni Hamburg     |
| admin@rzaix13.rrz.uni-hamburg.de |
+----------------------------------+




Author: dag@control.lth.se (Dag Bruck)
Date: 10 Feb 1995 16:22:29 GMT
Raw View
>>>>> "Paul" == Paul J Lucas <pjl@graceland.att.com> writes:

Paul> Now that bool is a built-in type, is the above defined in the
Paul> streams library?

Paul> If so, what are its semantics?  Does it try to parse the
Paul> stream of characters like:

Paul> false: 0,f,F,false,False,fAlSe, ...  true:
Paul> 1,t,T,true,True,tRuE, ...

In Paul's usual terse style: no.

If you pardon my ramblings, the answer is:

1.  If ios::boolalpha is false, the extractor expects either 0 or 1.
This is the default behaviour, for C compatibility.

2.  Otherwise the extractor expects one of two locale-dependent
strings.  For the default locale they are false and true.  The
matching is case-sensitive.

     -- Dag Bruck




Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Tue, 7 Feb 1995 16:09:35 GMT
Raw View
 Now that bool is a built-in type, is the above defined in the
 streams library?

 If so, what are its semantics?  Does it try to parse the stream
 of characters like:

  false: 0,f,F,false,False,fAlSe, ...
  true: 1,t,T,true,True,tRuE, ...

 Thanks.
--
 - Paul J. Lucas   #ifndef COMMON_KNOWLEDGE
   AT&T Bell Laboratories #include <stddisclaimer.h>
   Naperville, IL  #endif