1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 27.6.2 Output streams
35 #pragma GCC system_header
38 #include <ostream> // For flush()
42 template<typename _CharT, typename _Traits>
43 basic_istream<_CharT, _Traits>::sentry::
44 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
50 if (!__noskipws && (__in.flags() & ios_base::skipws))
52 const __int_type __eof = traits_type::eof();
53 __streambuf_type* __sb = __in.rdbuf();
54 __int_type __c = __sb->sgetc();
56 if (__in._M_check_facet(__in._M_fctype))
58 && __in._M_fctype->is(ctype_base::space, __c))
61 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
62 //195. Should basic_istream::sentry's constructor ever set eofbit?
64 __in.setstate(ios_base::eofbit);
74 __in.setstate(ios_base::failbit);
78 template<typename _CharT, typename _Traits>
79 basic_istream<_CharT, _Traits>&
80 basic_istream<_CharT, _Traits>::
81 operator>>(__istream_type& (*__pf)(__istream_type&))
87 template<typename _CharT, typename _Traits>
88 basic_istream<_CharT, _Traits>&
89 basic_istream<_CharT, _Traits>::
90 operator>>(__ios_type& (*__pf)(__ios_type&))
96 template<typename _CharT, typename _Traits>
97 basic_istream<_CharT, _Traits>&
98 basic_istream<_CharT, _Traits>::
99 operator>>(ios_base& (*__pf)(ios_base&))
105 template<typename _CharT, typename _Traits>
106 basic_istream<_CharT, _Traits>&
107 basic_istream<_CharT, _Traits>::
108 operator>>(bool& __n)
110 sentry __cerb(*this, false);
115 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
116 if (_M_check_facet(_M_fnumget))
117 _M_fnumget->get(*this, 0, *this, __err, __n);
118 this->setstate(__err);
120 catch(exception& __fail)
122 // 27.6.1.2.1 Common requirements.
123 // Turn this on without causing an ios::failure to be thrown.
124 this->setstate(ios_base::badbit);
125 if ((this->exceptions() & ios_base::badbit) != 0)
126 __throw_exception_again;
132 template<typename _CharT, typename _Traits>
133 basic_istream<_CharT, _Traits>&
134 basic_istream<_CharT, _Traits>::
135 operator>>(short& __n)
137 sentry __cerb(*this, false);
142 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
144 if (_M_check_facet(_M_fnumget))
145 _M_fnumget->get(*this, 0, *this, __err, __l);
146 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
147 // 118. basic_istream uses nonexistent num_get member functions.
148 if (!(__err & ios_base::failbit)
149 && (numeric_limits<short>::min() <= __l
150 && __l <= numeric_limits<short>::max()))
153 __err |= ios_base::failbit;
155 this->setstate(__err);
157 catch(exception& __fail)
159 // 27.6.1.2.1 Common requirements.
160 // Turn this on without causing an ios::failure to be thrown.
161 this->setstate(ios_base::badbit);
162 if ((this->exceptions() & ios_base::badbit) != 0)
163 __throw_exception_again;
169 template<typename _CharT, typename _Traits>
170 basic_istream<_CharT, _Traits>&
171 basic_istream<_CharT, _Traits>::
172 operator>>(unsigned short& __n)
174 sentry __cerb(*this, false);
179 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
180 if (_M_check_facet(_M_fnumget))
181 _M_fnumget->get(*this, 0, *this, __err, __n);
182 this->setstate(__err);
184 catch(exception& __fail)
186 // 27.6.1.2.1 Common requirements.
187 // Turn this on without causing an ios::failure to be thrown.
188 this->setstate(ios_base::badbit);
189 if ((this->exceptions() & ios_base::badbit) != 0)
190 __throw_exception_again;
196 template<typename _CharT, typename _Traits>
197 basic_istream<_CharT, _Traits>&
198 basic_istream<_CharT, _Traits>::
201 sentry __cerb(*this, false);
206 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
208 if (_M_check_facet(_M_fnumget))
209 _M_fnumget->get(*this, 0, *this, __err, __l);
210 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
211 // 118. basic_istream uses nonexistent num_get member functions.
212 if (!(__err & ios_base::failbit)
213 && (numeric_limits<int>::min() <= __l
214 && __l <= numeric_limits<int>::max()))
217 __err |= ios_base::failbit;
219 this->setstate(__err);
221 catch(exception& __fail)
223 // 27.6.1.2.1 Common requirements.
224 // Turn this on without causing an ios::failure to be thrown.
225 this->setstate(ios_base::badbit);
226 if ((this->exceptions() & ios_base::badbit) != 0)
227 __throw_exception_again;
233 template<typename _CharT, typename _Traits>
234 basic_istream<_CharT, _Traits>&
235 basic_istream<_CharT, _Traits>::
236 operator>>(unsigned int& __n)
238 sentry __cerb(*this, false);
243 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
244 if (_M_check_facet(_M_fnumget))
245 _M_fnumget->get(*this, 0, *this, __err, __n);
246 this->setstate(__err);
248 catch(exception& __fail)
250 // 27.6.1.2.1 Common requirements.
251 // Turn this on without causing an ios::failure to be thrown.
252 this->setstate(ios_base::badbit);
253 if ((this->exceptions() & ios_base::badbit) != 0)
254 __throw_exception_again;
260 template<typename _CharT, typename _Traits>
261 basic_istream<_CharT, _Traits>&
262 basic_istream<_CharT, _Traits>::
263 operator>>(long& __n)
265 sentry __cerb(*this, false);
270 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
271 if (_M_check_facet(_M_fnumget))
272 _M_fnumget->get(*this, 0, *this, __err, __n);
273 this->setstate(__err);
275 catch(exception& __fail)
277 // 27.6.1.2.1 Common requirements.
278 // Turn this on without causing an ios::failure to be thrown.
279 this->setstate(ios_base::badbit);
280 if ((this->exceptions() & ios_base::badbit) != 0)
281 __throw_exception_again;
287 template<typename _CharT, typename _Traits>
288 basic_istream<_CharT, _Traits>&
289 basic_istream<_CharT, _Traits>::
290 operator>>(unsigned long& __n)
292 sentry __cerb(*this, false);
297 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
298 if (_M_check_facet(_M_fnumget))
299 _M_fnumget->get(*this, 0, *this, __err, __n);
300 this->setstate(__err);
302 catch(exception& __fail)
304 // 27.6.1.2.1 Common requirements.
305 // Turn this on without causing an ios::failure to be thrown.
306 this->setstate(ios_base::badbit);
307 if ((this->exceptions() & ios_base::badbit) != 0)
308 __throw_exception_again;
314 #ifdef _GLIBCPP_USE_LONG_LONG
315 template<typename _CharT, typename _Traits>
316 basic_istream<_CharT, _Traits>&
317 basic_istream<_CharT, _Traits>::
318 operator>>(long long& __n)
320 sentry __cerb(*this, false);
325 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
326 if (_M_check_facet(_M_fnumget))
327 _M_fnumget->get(*this, 0, *this, __err, __n);
328 this->setstate(__err);
330 catch(exception& __fail)
332 // 27.6.1.2.1 Common requirements.
333 // Turn this on without causing an ios::failure to be thrown.
334 this->setstate(ios_base::badbit);
335 if ((this->exceptions() & ios_base::badbit) != 0)
336 __throw_exception_again;
342 template<typename _CharT, typename _Traits>
343 basic_istream<_CharT, _Traits>&
344 basic_istream<_CharT, _Traits>::
345 operator>>(unsigned long long& __n)
347 sentry __cerb(*this, false);
352 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
353 if (_M_check_facet(_M_fnumget))
354 _M_fnumget->get(*this, 0, *this, __err, __n);
355 this->setstate(__err);
357 catch(exception& __fail)
359 // 27.6.1.2.1 Common requirements.
360 // Turn this on without causing an ios::failure to be thrown.
361 this->setstate(ios_base::badbit);
362 if ((this->exceptions() & ios_base::badbit) != 0)
363 __throw_exception_again;
370 template<typename _CharT, typename _Traits>
371 basic_istream<_CharT, _Traits>&
372 basic_istream<_CharT, _Traits>::
373 operator>>(float& __n)
375 sentry __cerb(*this, false);
380 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
381 if (_M_check_facet(_M_fnumget))
382 _M_fnumget->get(*this, 0, *this, __err, __n);
383 this->setstate(__err);
385 catch(exception& __fail)
387 // 27.6.1.2.1 Common requirements.
388 // Turn this on without causing an ios::failure to be thrown.
389 this->setstate(ios_base::badbit);
390 if ((this->exceptions() & ios_base::badbit) != 0)
391 __throw_exception_again;
397 template<typename _CharT, typename _Traits>
398 basic_istream<_CharT, _Traits>&
399 basic_istream<_CharT, _Traits>::
400 operator>>(double& __n)
402 sentry __cerb(*this, false);
407 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
408 if (_M_check_facet(_M_fnumget))
409 _M_fnumget->get(*this, 0, *this, __err, __n);
410 this->setstate(__err);
412 catch(exception& __fail)
414 // 27.6.1.2.1 Common requirements.
415 // Turn this on without causing an ios::failure to be thrown.
416 this->setstate(ios_base::badbit);
417 if ((this->exceptions() & ios_base::badbit) != 0)
418 __throw_exception_again;
424 template<typename _CharT, typename _Traits>
425 basic_istream<_CharT, _Traits>&
426 basic_istream<_CharT, _Traits>::
427 operator>>(long double& __n)
429 sentry __cerb(*this, false);
434 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
435 if (_M_check_facet(_M_fnumget))
436 _M_fnumget->get(*this, 0, *this, __err, __n);
437 this->setstate(__err);
439 catch(exception& __fail)
441 // 27.6.1.2.1 Common requirements.
442 // Turn this on without causing an ios::failure to be thrown.
443 this->setstate(ios_base::badbit);
444 if ((this->exceptions() & ios_base::badbit) != 0)
445 __throw_exception_again;
451 template<typename _CharT, typename _Traits>
452 basic_istream<_CharT, _Traits>&
453 basic_istream<_CharT, _Traits>::
454 operator>>(void*& __n)
456 sentry __cerb(*this, false);
461 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
462 if (_M_check_facet(_M_fnumget))
463 _M_fnumget->get(*this, 0, *this, __err, __n);
464 this->setstate(__err);
466 catch(exception& __fail)
468 // 27.6.1.2.1 Common requirements.
469 // Turn this on without causing an ios::failure to be thrown.
470 this->setstate(ios_base::badbit);
471 if ((this->exceptions() & ios_base::badbit) != 0)
472 __throw_exception_again;
478 template<typename _CharT, typename _Traits>
479 basic_istream<_CharT, _Traits>&
480 basic_istream<_CharT, _Traits>::
481 operator>>(__streambuf_type* __sbout)
483 sentry __cerb(*this, false);
488 streamsize __xtrct = 0;
491 __streambuf_type* __sbin = this->rdbuf();
492 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
494 if (!__sbout || !__xtrct)
495 this->setstate(ios_base::failbit);
497 catch(exception& __fail)
499 // 27.6.2.5.1 Common requirements.
500 // Turn this on without causing an ios::failure to be thrown.
501 this->setstate(ios_base::badbit);
502 if ((this->exceptions() & ios_base::badbit) != 0)
503 __throw_exception_again;
509 template<typename _CharT, typename _Traits>
510 typename basic_istream<_CharT, _Traits>::int_type
511 basic_istream<_CharT, _Traits>::
514 const int_type __eof = traits_type::eof();
515 int_type __c = __eof;
517 sentry __cerb(*this, true);
522 __c = this->rdbuf()->sbumpc();
523 // 27.6.1.1 paragraph 3
527 this->setstate(ios_base::eofbit | ios_base::failbit);
529 catch(exception& __fail)
531 // 27.6.1.3 paragraph 1
532 // Turn this on without causing an ios::failure to be thrown.
533 this->setstate(ios_base::badbit);
534 if ((this->exceptions() & ios_base::badbit) != 0)
535 __throw_exception_again;
541 template<typename _CharT, typename _Traits>
542 basic_istream<_CharT, _Traits>&
543 basic_istream<_CharT, _Traits>::
547 sentry __cerb(*this, true);
552 const int_type __eof = traits_type::eof();
553 int_type __bufval = this->rdbuf()->sbumpc();
554 // 27.6.1.1 paragraph 3
555 if (__bufval != __eof)
558 __c = traits_type::to_char_type(__bufval);
561 this->setstate(ios_base::eofbit | ios_base::failbit);
563 catch(exception& __fail)
565 // 27.6.1.3 paragraph 1
566 // Turn this on without causing an ios::failure to be thrown.
567 this->setstate(ios_base::badbit);
568 if ((this->exceptions() & ios_base::badbit) != 0)
569 __throw_exception_again;
575 template<typename _CharT, typename _Traits>
576 basic_istream<_CharT, _Traits>&
577 basic_istream<_CharT, _Traits>::
578 get(char_type* __s, streamsize __n, char_type __delim)
581 sentry __cerb(*this, true);
586 const int_type __idelim = traits_type::to_int_type(__delim);
587 const int_type __eof = traits_type::eof();
588 __streambuf_type* __sb = this->rdbuf();
589 int_type __c = __sb->sgetc();
591 while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim)
593 *__s++ = traits_type::to_char_type(__c);
594 __c = __sb->snextc();
598 this->setstate(ios_base::eofbit);
600 catch(exception& __fail)
602 // 27.6.1.3 paragraph 1
603 // Turn this on without causing an ios::failure to be thrown.
604 this->setstate(ios_base::badbit);
605 if ((this->exceptions() & ios_base::badbit) != 0)
606 __throw_exception_again;
611 this->setstate(ios_base::failbit);
615 template<typename _CharT, typename _Traits>
616 basic_istream<_CharT, _Traits>&
617 basic_istream<_CharT, _Traits>::
618 get(__streambuf_type& __sb, char_type __delim)
621 sentry __cerb(*this, true);
626 const int_type __idelim = traits_type::to_int_type(__delim);
627 const int_type __eof = traits_type::eof();
628 __streambuf_type* __this_sb = this->rdbuf();
629 int_type __c = __this_sb->sgetc();
631 while (__c != __eof && __c != __idelim
632 && (__sb.sputc(traits_type::to_char_type(__c)) != __eof))
635 __c = __this_sb->snextc();
638 this->setstate(ios_base::eofbit);
640 catch(exception& __fail)
642 // 27.6.1.3 paragraph 1
643 // Turn this on without causing an ios::failure to be thrown.
644 this->setstate(ios_base::badbit);
645 if ((this->exceptions() & ios_base::badbit) != 0)
646 __throw_exception_again;
650 this->setstate(ios_base::failbit);
654 template<typename _CharT, typename _Traits>
655 basic_istream<_CharT, _Traits>&
656 basic_istream<_CharT, _Traits>::
657 getline(char_type* __s, streamsize __n, char_type __delim)
660 sentry __cerb(*this, true);
665 const int_type __idelim = traits_type::to_int_type(__delim);
666 const int_type __eof = traits_type::eof();
667 __streambuf_type* __sb = this->rdbuf();
668 int_type __c = __sb->sgetc();
670 while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim)
672 *__s++ = traits_type::to_char_type(__c);
673 __c = __sb->snextc();
677 this->setstate(ios_base::eofbit);
686 this->setstate(ios_base::failbit);
689 catch(exception& __fail)
691 // 27.6.1.3 paragraph 1
692 // Turn this on without causing an ios::failure to be thrown.
693 this->setstate(ios_base::badbit);
694 if ((this->exceptions() & ios_base::badbit) != 0)
695 __throw_exception_again;
700 this->setstate(ios_base::failbit);
704 template<typename _CharT, typename _Traits>
705 basic_istream<_CharT, _Traits>&
706 basic_istream<_CharT, _Traits>::
707 ignore(streamsize __n, int_type __delim)
710 sentry __cerb(*this, true);
711 if (__cerb && __n > 0)
715 const int_type __idelim = traits_type::to_int_type(__delim);
716 const int_type __eof = traits_type::eof();
717 __streambuf_type* __sb = this->rdbuf();
718 int_type __c = __sb->sbumpc();
719 bool __testdelim = __c == __idelim;
720 bool __testeof = __c == __eof;
722 __n = min(__n, numeric_limits<streamsize>::max());
723 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
726 __c = __sb->sbumpc();
727 __testeof = __c == __eof;
728 __testdelim = __c == __idelim;
730 if ((_M_gcount == __n - 1 && !__testeof) || __testdelim)
733 this->setstate(ios_base::eofbit);
735 catch(exception& __fail)
737 // 27.6.1.3 paragraph 1
738 // Turn this on without causing an ios::failure to be thrown.
739 this->setstate(ios_base::badbit);
740 if ((this->exceptions() & ios_base::badbit) != 0)
741 __throw_exception_again;
747 template<typename _CharT, typename _Traits>
748 typename basic_istream<_CharT, _Traits>::int_type
749 basic_istream<_CharT, _Traits>::
752 int_type __c = traits_type::eof();
754 sentry __cerb(*this, true);
758 { __c = this->rdbuf()->sgetc(); }
759 catch(exception& __fail)
761 // 27.6.1.3 paragraph 1
762 // Turn this on without causing an ios::failure to be thrown.
763 this->setstate(ios_base::badbit);
764 if ((this->exceptions() & ios_base::badbit) != 0)
765 __throw_exception_again;
771 template<typename _CharT, typename _Traits>
772 basic_istream<_CharT, _Traits>&
773 basic_istream<_CharT, _Traits>::
774 read(char_type* __s, streamsize __n)
777 sentry __cerb(*this, true);
784 const int_type __eof = traits_type::eof();
785 __streambuf_type* __sb = this->rdbuf();
786 int_type __c = __sb->sbumpc();
787 bool __testeof = __c == __eof;
789 while (_M_gcount < __n - 1 && !__testeof)
791 *__s++ = traits_type::to_char_type(__c);
793 __c = __sb->sbumpc();
794 __testeof = __c == __eof;
797 this->setstate(ios_base::eofbit | ios_base::failbit);
800 // _M_gcount == __n - 1
801 *__s++ = traits_type::to_char_type(__c);
805 catch(exception& __fail)
807 // 27.6.1.3 paragraph 1
808 // Turn this on without causing an ios::failure to be thrown.
809 this->setstate(ios_base::badbit);
810 if ((this->exceptions() & ios_base::badbit) != 0)
811 __throw_exception_again;
816 this->setstate(ios_base::failbit);
820 template<typename _CharT, typename _Traits>
822 basic_istream<_CharT, _Traits>::
823 readsome(char_type* __s, streamsize __n)
825 const int_type __eof = traits_type::eof();
827 sentry __cerb(*this, true);
834 streamsize __num = this->rdbuf()->in_avail();
835 if (__num != static_cast<streamsize>(__eof))
837 __num = min(__num, __n);
838 _M_gcount = this->rdbuf()->sgetn(__s, __num);
841 this->setstate(ios_base::eofbit);
843 catch(exception& __fail)
845 // 27.6.1.3 paragraph 1
846 // Turn this on without causing an ios::failure to be thrown.
847 this->setstate(ios_base::badbit);
848 if ((this->exceptions() & ios_base::badbit) != 0)
849 __throw_exception_again;
854 this->setstate(ios_base::failbit);
858 template<typename _CharT, typename _Traits>
859 basic_istream<_CharT, _Traits>&
860 basic_istream<_CharT, _Traits>::
861 putback(char_type __c)
863 sentry __cerb(*this, true);
868 const int_type __eof = traits_type::eof();
869 __streambuf_type* __sb = this->rdbuf();
870 if (!__sb || __sb->sputbackc(__c) == __eof)
871 this->setstate(ios_base::badbit);
873 catch(exception& __fail)
875 // 27.6.1.3 paragraph 1
876 // Turn this on without causing an ios::failure to be thrown.
877 this->setstate(ios_base::badbit);
878 if ((this->exceptions() & ios_base::badbit) != 0)
879 __throw_exception_again;
883 this->setstate(ios_base::failbit);
887 template<typename _CharT, typename _Traits>
888 basic_istream<_CharT, _Traits>&
889 basic_istream<_CharT, _Traits>::
893 sentry __cerb(*this, true);
898 const int_type __eof = traits_type::eof();
899 __streambuf_type* __sb = this->rdbuf();
900 if (!__sb || __eof == __sb->sungetc())
901 this->setstate(ios_base::badbit);
903 catch(exception& __fail)
905 // 27.6.1.3 paragraph 1
906 // Turn this on without causing an ios::failure to be thrown.
907 this->setstate(ios_base::badbit);
908 if ((this->exceptions() & ios_base::badbit) != 0)
909 __throw_exception_again;
913 this->setstate(ios_base::failbit);
917 template<typename _CharT, typename _Traits>
919 basic_istream<_CharT, _Traits>::
922 int __ret = traits_type::eof();
924 sentry __cerb(*this, true);
929 __streambuf_type* __sb = this->rdbuf();
930 if (!__sb || __ret == __sb->pubsync())
931 this->setstate(ios_base::badbit);
935 catch(exception& __fail)
937 // 27.6.1.3 paragraph 1
938 // Turn this on without causing an ios::failure to be thrown.
939 this->setstate(ios_base::badbit);
940 if ((this->exceptions() & ios_base::badbit) != 0)
941 __throw_exception_again;
947 template<typename _CharT, typename _Traits>
948 typename basic_istream<_CharT, _Traits>::pos_type
949 basic_istream<_CharT, _Traits>::
952 pos_type __ret = pos_type(-1);
954 sentry __cerb(*this, true);
959 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
961 catch(exception& __fail)
963 // 27.6.1.3 paragraph 1
964 // Turn this on without causing an ios::failure to be thrown.
965 this->setstate(ios_base::badbit);
966 if ((this->exceptions() & ios_base::badbit) != 0)
967 __throw_exception_again;
974 template<typename _CharT, typename _Traits>
975 basic_istream<_CharT, _Traits>&
976 basic_istream<_CharT, _Traits>::
977 seekg(pos_type __pos)
980 sentry __cerb(*this, true);
985 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
986 // 136. seekp, seekg setting wrong streams?
987 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
989 // 129. Need error indication from seekp() and seekg()
990 if (__err == pos_type(off_type(-1)))
991 this->setstate(ios_base::failbit);
994 catch(exception& __fail)
996 // 27.6.1.3 paragraph 1
997 // Turn this on without causing an ios::failure to be thrown.
998 this->setstate(ios_base::badbit);
999 if ((this->exceptions() & ios_base::badbit) != 0)
1000 __throw_exception_again;
1006 template<typename _CharT, typename _Traits>
1007 basic_istream<_CharT, _Traits>&
1008 basic_istream<_CharT, _Traits>::
1009 seekg(off_type __off, ios_base::seekdir __dir)
1012 sentry __cerb(*this, true);
1017 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1018 // 136. seekp, seekg setting wrong streams?
1019 pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
1022 // 129. Need error indication from seekp() and seekg()
1023 if (__err == pos_type(off_type(-1)))
1024 this->setstate(ios_base::failbit);
1027 catch(exception& __fail)
1029 // 27.6.1.3 paragraph 1
1030 // Turn this on without causing an ios::failure to be thrown.
1031 this->setstate(ios_base::badbit);
1032 if ((this->exceptions() & ios_base::badbit) != 0)
1033 __throw_exception_again;
1039 // 27.6.1.2.3 Character extraction templates
1040 template<typename _CharT, typename _Traits>
1041 basic_istream<_CharT, _Traits>&
1042 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
1044 typedef basic_istream<_CharT, _Traits> __istream_type;
1045 typename __istream_type::sentry __cerb(__in, false);
1050 catch(exception& __fail)
1052 // 27.6.1.2.1 Common requirements.
1053 // Turn this on without causing an ios::failure to be thrown.
1054 __in.setstate(ios_base::badbit);
1055 if ((__in.exceptions() & ios_base::badbit) != 0)
1056 __throw_exception_again;
1060 __in.setstate(ios_base::failbit);
1064 template<typename _CharT, typename _Traits>
1065 basic_istream<_CharT, _Traits>&
1066 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1068 typedef basic_istream<_CharT, _Traits> __istream_type;
1069 typedef typename __istream_type::__streambuf_type __streambuf_type;
1070 typedef typename _Traits::int_type int_type;
1071 typedef _CharT char_type;
1072 typedef ctype<_CharT> __ctype_type;
1073 streamsize __extracted = 0;
1075 typename __istream_type::sentry __cerb(__in, false);
1080 // Figure out how many characters to extract.
1081 streamsize __num = __in.width();
1083 __num = numeric_limits<streamsize>::max();
1085 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1086 const int_type __eof = _Traits::eof();
1087 __streambuf_type* __sb = __in.rdbuf();
1088 int_type __c = __sb->sgetc();
1090 while (__extracted < __num - 1
1091 && __c != __eof && !__ctype.is(ctype_base::space, __c))
1095 __c = __sb->snextc();
1098 __in.setstate(ios_base::eofbit);
1100 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1101 //68. Extractors for char* should store null at end
1106 catch(exception& __fail)
1108 // 27.6.1.2.1 Common requirements.
1109 // Turn this on without causing an ios::failure to be thrown.
1110 __in.setstate(ios_base::badbit);
1111 if ((__in.exceptions() & ios_base::badbit) != 0)
1112 __throw_exception_again;
1116 __in.setstate(ios_base::failbit);
1120 // 27.6.1.4 Standard basic_istream manipulators
1121 template<typename _CharT, typename _Traits>
1122 basic_istream<_CharT,_Traits>&
1123 ws(basic_istream<_CharT,_Traits>& __in)
1125 typedef basic_istream<_CharT, _Traits> __istream_type;
1126 typedef typename __istream_type::__streambuf_type __streambuf_type;
1127 typedef typename __istream_type::__ctype_type __ctype_type;
1128 typedef typename __istream_type::int_type __int_type;
1130 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1131 const __int_type __eof = _Traits::eof();
1132 __streambuf_type* __sb = __in.rdbuf();
1133 __int_type __c = __sb->sgetc();
1135 while (__c != __eof && __ctype.is(ctype_base::space, __c))
1136 __c = __sb->snextc();
1138 __in.setstate(ios_base::eofbit);
1143 // 21.3.7.9 basic_string::getline and operators
1144 template<typename _CharT, typename _Traits, typename _Alloc>
1145 basic_istream<_CharT, _Traits>&
1146 operator>>(basic_istream<_CharT, _Traits>& __in,
1147 basic_string<_CharT, _Traits, _Alloc>& __str)
1149 typedef basic_istream<_CharT, _Traits> __istream_type;
1150 typedef typename __istream_type::int_type __int_type;
1151 typedef typename __istream_type::__streambuf_type __streambuf_type;
1152 typedef typename __istream_type::__ctype_type __ctype_type;
1153 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1154 typedef typename __string_type::size_type __size_type;
1155 __size_type __extracted = 0;
1157 typename __istream_type::sentry __cerb(__in, false);
1161 streamsize __w = __in.width();
1163 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1165 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1166 const __int_type __eof = _Traits::eof();
1167 __streambuf_type* __sb = __in.rdbuf();
1168 __int_type __c = __sb->sgetc();
1170 while (__extracted < __n
1171 && __c != __eof && !__ctype.is(ctype_base::space, __c))
1173 __str += _Traits::to_char_type(__c);
1175 __c = __sb->snextc();
1178 __in.setstate(ios_base::eofbit);
1181 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1182 //211. operator>>(istream&, string&) doesn't set failbit
1184 __in.setstate (ios_base::failbit);
1189 template<typename _CharT, typename _Traits, typename _Alloc>
1190 basic_istream<_CharT, _Traits>&
1191 getline(basic_istream<_CharT, _Traits>& __in,
1192 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1194 typedef basic_istream<_CharT, _Traits> __istream_type;
1195 typedef typename __istream_type::int_type __int_type;
1196 typedef typename __istream_type::__streambuf_type __streambuf_type;
1197 typedef typename __istream_type::__ctype_type __ctype_type;
1198 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1199 typedef typename __string_type::size_type __size_type;
1201 __size_type __extracted = 0;
1202 bool __testdelim = false;
1203 typename __istream_type::sentry __cerb(__in, true);
1207 __size_type __n = __str.max_size();
1209 __int_type __idelim = _Traits::to_int_type(__delim);
1210 __streambuf_type* __sb = __in.rdbuf();
1211 __int_type __c = __sb->sbumpc();
1212 const __int_type __eof = _Traits::eof();
1213 __testdelim = __c == __idelim;
1215 while (__extracted <= __n && __c != __eof && !__testdelim)
1217 __str += _Traits::to_char_type(__c);
1219 __c = __sb->sbumpc();
1220 __testdelim = __c == __idelim;
1223 __in.setstate(ios_base::eofbit);
1225 if (!__extracted && !__testdelim)
1226 __in.setstate(ios_base::failbit);
1230 template<class _CharT, class _Traits, class _Alloc>
1231 inline basic_istream<_CharT,_Traits>&
1232 getline(basic_istream<_CharT, _Traits>& __in,
1233 basic_string<_CharT,_Traits,_Alloc>& __str)
1234 { return getline(__in, __str, __in.widen('\n')); }
1236 // Inhibit implicit instantiations for required instantiations,
1237 // which are defined via explicit instantiations elsewhere.
1238 // NB: This syntax is a GNU extension.
1239 extern template class basic_istream<char>;
1240 extern template istream& ws(istream&);
1241 extern template istream& operator>>(istream&, char&);
1242 extern template istream& operator>>(istream&, char*);
1243 extern template istream& operator>>(istream&, unsigned char&);
1244 extern template istream& operator>>(istream&, signed char&);
1245 extern template istream& operator>>(istream&, unsigned char*);
1246 extern template istream& operator>>(istream&, signed char*);
1248 extern template class basic_istream<wchar_t>;
1249 extern template wistream& ws(wistream&);
1250 extern template wistream& operator>>(wistream&, wchar_t&);
1251 extern template wistream& operator>>(wistream&, wchar_t*);