Topic: effect of stream state on extraction


Author: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: 2000/09/20
Raw View
Hi,
In article <39c7ec29.13791993@news.csrlink.net>,
  jpotter@falcon.lhup.edu (John Potter) wrote:
> I find it rather strange that if cin contains only whitespace the
> expected output would be '<> <world>'.
>
> The new paragraph says that a null character will be inserted.  It
does
> not say anything about the sentry being true nor about any attempt to
> extract characters.  It seems to be unconditional.

Hm, maybe a defect report is in order... I thought there was a defect
report on the section(s) for the general description of formatted and
unformatted input anyway to state what is going to happen if only
'eofbit' is set in the state: It should set 'failbit'. I'm not sure
whether the standard really says so.
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>


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: jpotter@falcon.lhup.edu (John Potter)
Date: 2000/09/20
Raw View
On Wed, 20 Sep 2000 16:38:03 GMT, Dietmar Kuehl
<dietmar_kuehl@yahoo.com> wrote:

> In article <39c7ec29.13791993@news.csrlink.net>,
>   jpotter@falcon.lhup.edu (John Potter) wrote:
> > I find it rather strange that if cin contains only whitespace the
> > expected output would be '<> <world>'.
> >
> > The new paragraph says that a null character will be inserted.  It
> does
> > not say anything about the sentry being true nor about any attempt to
> > extract characters.  It seems to be unconditional.
>
> Hm, maybe a defect report is in order... I thought there was a defect
> report on the section(s) for the general description of formatted and
> unformatted input anyway to state what is going to happen if only
> 'eofbit' is set in the state: It should set 'failbit'. I'm not sure
> whether the standard really says so.

I think that you also find that strange.  Neither of us has said what
we do expect.  I think that you expect <hello> <world>.  I expect <> <>.
Assuming no exceptions thrown, I read these operations as

   sentry s(is);
   if (s)
      do extraction stuff
   else
      set failbit
   store null character

I don't see the 'catch all' as overpowering the unconditional 'in any
case, a null character is stored'.  If the sentry does not give true,
no attempt to extract will occur and failbit will be set by the
function.  Again, it is not conditional upon a good sentry.  I didn't
find anything that said eofbit would be set when eof occured, but assume
I just missed that.

I checked one classic iostream which gave me what I expected, but have
not had a chance to test any standard stream.  I leave any DR to you,
but would like to know if my above interpretation is wrong.

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






Author: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: 2000/09/21
Raw View
Hi,
In article <39c936cd.9130571@news.csrlink.net>,
  jpotter@falcon.lhup.edu (John Potter) wrote:
> I think that you also find that strange.  Neither of us has said what
> we do expect.  I think that you expect <hello> <world>.  I expect <>
> <>. Assuming no exceptions thrown, I read these operations as
>
>    sentry s(is);
>    if (s)
>       do extraction stuff
>    else
>       set failbit
>    store null character

I disagree with the "store null character" part: I'm reading the
[corrected] standard to mean

  sentry s(is);
  if (s) {
    do extraction stuff
    store null character
  }
  else
    set failbit

However, the standard does not explicitly support one approach or the
other: It is simply silent as what is really meant.

> I didn't find anything that said eofbit would be set when eof
> occured, but assume I just missed that.

It is in one of those "catch all" section: 27.6.1.1 paragraph 3.
>
> I checked one classic iostream which gave me what I expected, but have
> not had a chance to test any standard stream.  I leave any DR to you,
> but would like to know if my above interpretation is wrong.

I expected the output "<> <world>" but I should have checked my
implementation first: I get "<> <>" with Dinkumware and my
implementation. That is, I interpreted the same thing differently...
Anyway, I don't think that it is clearly saying what is supposed to be
going on... What the right behavior should be I don't really know.
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>


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: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: 2000/09/18
Raw View
Hi,
In article <39C2D2E3.EE683BE6@hotmail.com>,
  anupam kapoor <anupamk@hotmail.com> wrote:
> what is the content of the variable if extraction fails ?

In general, the variable is not modified if 'failbit' or 'badbit' is
set. Personally, I would prefer it overflow or underflow would be
indicated separately, however, eg. by setting 'failbit' and changing
the value to 'std::numeric_limits<T>::max()' or '...::min().

> i.e. can i say that if, for example ios_base::badbit or
> ios_base::failbit is set, all subsequent extractors will leave
> the variable in a sane state e.g. T() for a variable of type
> T ?

If the state is not 'goodbit', no extractor will touch the value of the
variables. They stay unchanged. That is, if you want to have 'T()' in
there, you should fill it in first.
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>


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: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 19 Sep 00 04:06:14 GMT
Raw View
In article <39C2D2E3.EE683BE6@hotmail.com>, anupam kapoor
<anupamk@hotmail.com> writes
>hi all,
>
>a quick question for the gurus on the list :
>
>extractors read vlaues from an input stream and place it into a
>variable. what is the content of the variable if extraction fails ? i.e.
>can i say that if, for example ios_base::badbit or ios_base::failbit is
>set, all subsequent extractors will leave the variable in a sane state
>e.g. T() for a variable of type T ?
>
>if not, can someone please let me know, why this is not the case ?

IIRC it should do nothing. If your variable was in a sane state it
should still be, if it wasn't it won't be. This means that you can
detect failure and roll back to where you were.


Francis Glassborow      Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ 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: jpotter@falcon.lhup.edu (John Potter)
Date: 2000/09/19
Raw View
On 18 Sep 2000 14:36:03 -0400, Dietmar Kuehl <dietmar_kuehl@yahoo.com>
wrote:

> If the state is not 'goodbit', no extractor will touch the value of the
> variables. They stay unchanged. That is, if you want to have 'T()' in
> there, you should fill it in first.

C_string seems to be an exception.  My read is that both >> and getline
will insert a null character even when nothing else happens.  Am I
misreading it?

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






Author: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: 2000/09/19
Raw View
Hi,
In article <39c68bcd.6478752@news.csrlink.net>,
  jpotter@falcon.lhup.edu (John Potter) wrote:
> C_string seems to be an exception.

I assume you are referring to the description of the input operator
after applying the changes from the defect report (otherwise it is
rather unclear what is supposed to happen although the semantics are
pretty clear).

First of all, if the stream state was not 'goodbit' on entry, there
will be no effect on the object due to the "catch all" describing
formatted or unformatted input: If the 'sentry' does not convert to
'true', nothing will happen to the object because the individual
description do not apply.

Other than that, you are however right that 'failbit' might be set and
at the same time the string pointed to is still set: If no character
could be extracted. Actually, I think it is good that way because I
think that numeric overflow/underflow should also change the value to
indicate the source of the failure (overflow/underflow vs. some other
error, eg. format error or end of file).
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>


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: jpotter@falcon.lhup.edu (John Potter)
Date: 2000/09/19
Raw View
On Tue, 19 Sep 2000 19:15:15 GMT, Dietmar Kuehl
<dietmar_kuehl@yahoo.com> wrote:

> Hi,
> In article <39c68bcd.6478752@news.csrlink.net>,
>   jpotter@falcon.lhup.edu (John Potter) wrote:
> > C_string seems to be an exception.
>
> I assume you are referring to the description of the input operator
> after applying the changes from the defect report (otherwise it is
> rather unclear what is supposed to happen although the semantics are
> pretty clear).

Yes, after the DR is better.

> First of all, if the stream state was not 'goodbit' on entry, there
> will be no effect on the object due to the "catch all" describing
> formatted or unformatted input: If the 'sentry' does not convert to
> 'true', nothing will happen to the object because the individual
> description do not apply.

That's a nice paraphrase; however, another reading is possible.  It
says that if the 'sentry' does convert to 'true' it will attempt to
extract characters.  It does not say that nothing will be done
otherwise.

    char a[] = "hello", b[] = "world";
    cin >> a >> b;
    cout << '<' << a << "> <" << b << ">\n";

I find it rather strange that if cin contains only whitespace the
expected output would be '<> <world>'.

The new paragraph says that a null character will be inserted.  It does
not say anything about the sentry being true nor about any attempt to
extract characters.  It seems to be unconditional.

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






Author: anupam kapoor <anupamk@hotmail.com>
Date: 2000/09/17
Raw View
hi all,

a quick question for the gurus on the list :

extractors read vlaues from an input stream and place it into
a variable. what is the content of the variable if extraction
fails ? i.e. can i say that if, for example ios_base::badbit or
ios_base::failbit is set, all subsequent extractors will leave
the variable in a sane state e.g. T() for a variable of type
T ?

if not, can someone please let me know, why this is not
the case ?


thank you

anupam






      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

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