This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Strange behaviour of "cin"
- From: "Arun Saini , Gurgaon" <arun at ggn dot hcltech dot com>
- To: libstdc++ at gcc dot gnu dot org
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 15 Feb 2002 21:56:26 +0530
- Subject: Strange behaviour of "cin"
I have a program where "cin" fails. I tried tracing through the call using
gdb.
I provide the trace below.
575 cin >> selection;
(gdb) s
_ZNSirsERi (this=0x80545840, __n=@0x8047c98) at istream.tcc:185
185 sentry __cerb(*this, false);
(gdb) s
sentry (this=0x8047c4f, __in=@0x80545840, __noskipws=false) at
istream.tcc:41
41 if (__in.good())
(gdb) n
43 if (__in.tie())
(gdb)
44 __in.tie()->flush();
(gdb)
45 if (!__noskipws && (__in.flags() & ios_base::skipws))
(gdb)
47 const __int_type __eof = traits_type::eof();
(gdb)
48 const __ctype_type* __ctype =
__in._M_get_fctype_ios();
(gdb)
49 __streambuf_type* __sb = __in.rdbuf();
(gdb)
50 __int_type __c = __sb->sgetc();
(gdb)
52 while (__c != __eof && __ctype->is(ctype_base::space,
__c))
(gdb)
57 if (__c == __eof)
(gdb)
63 if (__in.good())
(gdb)
64 _M_ok = true;
(gdb)
0x8053bfd 68 __in.setstate(ios_base::failbit);
The last statement is surprising since we see from the previous statements
that the goodbit was set.
Any ideas why the failbit is getting set.
I am using cc 3.0.3 and the libstdc++ that comes along with it on SCO 5.0.5.
A snipet from the file istream.tcc, whose trace is given above, is provided
below.
37 template<typename _CharT, typename _Traits>
38 basic_istream<_CharT, _Traits>::sentry::
39 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
40 {
>> 41 if (__in.good())
42 {
>> 43 if (__in.tie())
>> 44 __in.tie()->flush();
>> 45 if (!__noskipws && (__in.flags() & ios_base::skipws))
46 {
>> 47 const __int_type __eof = traits_type::eof();
>> 48 const __ctype_type* __ctype =
__in._M_get_fctype_ios();
>> 49 __streambuf_type* __sb = __in.rdbuf();
>> 50 __int_type __c = __sb->sgetc();
51
>> 52 while (__c != __eof && __ctype->is(ctype_base::space,
__c))
53 __c = __sb->snextc();
54
55 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
56 //195. Should basic_istream::sentry's constructor ever set eofbit?
>> 57 if (__c == __eof)
58 __in.setstate(ios_base::eofbit);
59 #endif
60 }
61 }
62
>> 63 if (__in.good())
>> 64 _M_ok = true;
65 else
66 {
67 _M_ok = false;
?? 68 __in.setstate(ios_base::failbit);
69 }
70 }
Regards
Arun Saini