Another problem with istringstream
Haruhiko Okumura
okumura@matsusaka-u.ac.jp
Sat Apr 1 00:00:00 GMT 2000
From: Benjamin Kosnik <bkoz@cygnus.com>
Subject: re: Another problem with istringstream
Date: Tue, 11 Jan 2000 23:09:14 -0800
> Thanks for the elaborated test case. What do you think the output
> should be, and why? There has been a defect report (195) that
> explicitly sets failbit | eofbit in the istream::sentry ctor -- that's
> why there might be some confusion WRT the standard. I've asked for
> clarification on this point, and will let you know what I find out.
>
> Take a look at this pared-down example based on your last post. I
> believe the current behavior is odd, but conformant to the standard +
> defect patches. I would think that only eofbit should be set for both
> of the two cases below, but that is not strictly conformant.
I'm now beginning to understand what the point is. My
(mis)understanding was that
if (cin >> x) do_something_with(x);
should be synonymous to
if (scanf("%d", &x) == 1) do_something_with(x);
I've seen constructs like "if (cin >> x) ..." many times (even in the
Standard and Stroustrup's code) and I took that they behave as common
sense would suggest.
What you wrote is very clear, but as for the Standard it's not as
clear to me yet. Is it not that "input operation failed because eof
is reached"? Is it that "input didn't fail, it only reached eof"?
Sorry for my poor expression. I hope you understand my mixed feeling
with the Standard.
--
Haruhiko Okumura <okumura@matsusaka-u.ac.jp>
Matsusaka University, 1846 Kubo-cho, Matsusaka, 515-8511 Japan
Phone: +81-598-29-1122 Fax: +81-598-29-1014
http://www.matsusaka-u.ac.jp/~okumura/
More information about the Libstdc++
mailing list