1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
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
36 #define _ISTREAM_TCC 1
38 #pragma GCC system_header
41 #include <ostream> // For flush()
45 template<typename _CharT, typename _Traits>
46 basic_istream<_CharT, _Traits>::sentry::
47 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
53 if (!__noskipws && (__in.flags() & ios_base::skipws))
55 const __int_type __eof = traits_type::eof();
56 __streambuf_type* __sb = __in.rdbuf();
57 __int_type __c = __sb->sgetc();
59 const __ctype_type& __ct = __check_facet(__in._M_ctype);
60 while (!traits_type::eq_int_type(__c, __eof)
61 && __ct.is(ctype_base::space,
62 traits_type::to_char_type(__c)))
65 // _GLIBCXX_RESOLVE_LIB_DEFECTS
66 // 195. Should basic_istream::sentry's constructor ever set eofbit?
67 if (traits_type::eq_int_type(__c, __eof))
68 __in.setstate(ios_base::eofbit);
77 __in.setstate(ios_base::failbit);
81 template<typename _CharT, typename _Traits>
82 basic_istream<_CharT, _Traits>&
83 basic_istream<_CharT, _Traits>::
84 operator>>(__istream_type& (*__pf)(__istream_type&))
90 template<typename _CharT, typename _Traits>
91 basic_istream<_CharT, _Traits>&
92 basic_istream<_CharT, _Traits>::
93 operator>>(__ios_type& (*__pf)(__ios_type&))
99 template<typename _CharT, typename _Traits>
100 basic_istream<_CharT, _Traits>&
101 basic_istream<_CharT, _Traits>::
102 operator>>(ios_base& (*__pf)(ios_base&))
108 template<typename _CharT, typename _Traits>
109 basic_istream<_CharT, _Traits>&
110 basic_istream<_CharT, _Traits>::
111 operator>>(bool& __n)
113 sentry __cerb(*this, false);
118 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
119 const __num_get_type& __ng = __check_facet(this->_M_num_get);
120 __ng.get(*this, 0, *this, __err, __n);
121 this->setstate(__err);
125 // 27.6.1.2.1 Common requirements.
126 // Turn this on without causing an ios::failure to be thrown.
127 this->_M_setstate(ios_base::badbit);
128 if ((this->exceptions() & ios_base::badbit) != 0)
129 __throw_exception_again;
135 template<typename _CharT, typename _Traits>
136 basic_istream<_CharT, _Traits>&
137 basic_istream<_CharT, _Traits>::
138 operator>>(short& __n)
140 sentry __cerb(*this, false);
146 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
147 const __num_get_type& __ng = __check_facet(this->_M_num_get);
148 __ng.get(*this, 0, *this, __err, __l);
149 // _GLIBCXX_RESOLVE_LIB_DEFECTS
150 // 118. basic_istream uses nonexistent num_get member functions.
151 if (!(__err & ios_base::failbit)
152 && (numeric_limits<short>::min() <= __l
153 && __l <= numeric_limits<short>::max()))
156 __err |= ios_base::failbit;
157 this->setstate(__err);
161 // 27.6.1.2.1 Common requirements.
162 // Turn this on without causing an ios::failure to be thrown.
163 this->_M_setstate(ios_base::badbit);
164 if ((this->exceptions() & ios_base::badbit) != 0)
165 __throw_exception_again;
171 template<typename _CharT, typename _Traits>
172 basic_istream<_CharT, _Traits>&
173 basic_istream<_CharT, _Traits>::
174 operator>>(unsigned short& __n)
176 sentry __cerb(*this, false);
181 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
182 const __num_get_type& __ng = __check_facet(this->_M_num_get);
183 __ng.get(*this, 0, *this, __err, __n);
184 this->setstate(__err);
188 // 27.6.1.2.1 Common requirements.
189 // Turn this on without causing an ios::failure to be thrown.
190 this->_M_setstate(ios_base::badbit);
191 if ((this->exceptions() & ios_base::badbit) != 0)
192 __throw_exception_again;
198 template<typename _CharT, typename _Traits>
199 basic_istream<_CharT, _Traits>&
200 basic_istream<_CharT, _Traits>::
203 sentry __cerb(*this, false);
209 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
210 const __num_get_type& __ng = __check_facet(this->_M_num_get);
211 __ng.get(*this, 0, *this, __err, __l);
212 // _GLIBCXX_RESOLVE_LIB_DEFECTS
213 // 118. basic_istream uses nonexistent num_get member functions.
214 if (!(__err & ios_base::failbit)
215 && (numeric_limits<int>::min() <= __l
216 && __l <= numeric_limits<int>::max()))
219 __err |= ios_base::failbit;
220 this->setstate(__err);
224 // 27.6.1.2.1 Common requirements.
225 // Turn this on without causing an ios::failure to be thrown.
226 this->_M_setstate(ios_base::badbit);
227 if ((this->exceptions() & ios_base::badbit) != 0)
228 __throw_exception_again;
234 template<typename _CharT, typename _Traits>
235 basic_istream<_CharT, _Traits>&
236 basic_istream<_CharT, _Traits>::
237 operator>>(unsigned int& __n)
239 sentry __cerb(*this, false);
244 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
245 const __num_get_type& __ng = __check_facet(this->_M_num_get);
246 __ng.get(*this, 0, *this, __err, __n);
247 this->setstate(__err);
251 // 27.6.1.2.1 Common requirements.
252 // Turn this on without causing an ios::failure to be thrown.
253 this->_M_setstate(ios_base::badbit);
254 if ((this->exceptions() & ios_base::badbit) != 0)
255 __throw_exception_again;
261 template<typename _CharT, typename _Traits>
262 basic_istream<_CharT, _Traits>&
263 basic_istream<_CharT, _Traits>::
264 operator>>(long& __n)
266 sentry __cerb(*this, false);
271 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
272 const __num_get_type& __ng = __check_facet(this->_M_num_get);
273 __ng.get(*this, 0, *this, __err, __n);
274 this->setstate(__err);
278 // 27.6.1.2.1 Common requirements.
279 // Turn this on without causing an ios::failure to be thrown.
280 this->_M_setstate(ios_base::badbit);
281 if ((this->exceptions() & ios_base::badbit) != 0)
282 __throw_exception_again;
288 template<typename _CharT, typename _Traits>
289 basic_istream<_CharT, _Traits>&
290 basic_istream<_CharT, _Traits>::
291 operator>>(unsigned long& __n)
293 sentry __cerb(*this, false);
298 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
299 const __num_get_type& __ng = __check_facet(this->_M_num_get);
300 __ng.get(*this, 0, *this, __err, __n);
301 this->setstate(__err);
305 // 27.6.1.2.1 Common requirements.
306 // Turn this on without causing an ios::failure to be thrown.
307 this->_M_setstate(ios_base::badbit);
308 if ((this->exceptions() & ios_base::badbit) != 0)
309 __throw_exception_again;
315 #ifdef _GLIBCXX_USE_LONG_LONG
316 template<typename _CharT, typename _Traits>
317 basic_istream<_CharT, _Traits>&
318 basic_istream<_CharT, _Traits>::
319 operator>>(long long& __n)
321 sentry __cerb(*this, false);
326 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
327 const __num_get_type& __ng = __check_facet(this->_M_num_get);
328 __ng.get(*this, 0, *this, __err, __n);
329 this->setstate(__err);
333 // 27.6.1.2.1 Common requirements.
334 // Turn this on without causing an ios::failure to be thrown.
335 this->_M_setstate(ios_base::badbit);
336 if ((this->exceptions() & ios_base::badbit) != 0)
337 __throw_exception_again;
343 template<typename _CharT, typename _Traits>
344 basic_istream<_CharT, _Traits>&
345 basic_istream<_CharT, _Traits>::
346 operator>>(unsigned long long& __n)
348 sentry __cerb(*this, false);
353 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
354 const __num_get_type& __ng = __check_facet(this->_M_num_get);
355 __ng.get(*this, 0, *this, __err, __n);
356 this->setstate(__err);
360 // 27.6.1.2.1 Common requirements.
361 // Turn this on without causing an ios::failure to be thrown.
362 this->_M_setstate(ios_base::badbit);
363 if ((this->exceptions() & ios_base::badbit) != 0)
364 __throw_exception_again;
371 template<typename _CharT, typename _Traits>
372 basic_istream<_CharT, _Traits>&
373 basic_istream<_CharT, _Traits>::
374 operator>>(float& __n)
376 sentry __cerb(*this, false);
381 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
382 const __num_get_type& __ng = __check_facet(this->_M_num_get);
383 __ng.get(*this, 0, *this, __err, __n);
384 this->setstate(__err);
388 // 27.6.1.2.1 Common requirements.
389 // Turn this on without causing an ios::failure to be thrown.
390 this->_M_setstate(ios_base::badbit);
391 if ((this->exceptions() & ios_base::badbit) != 0)
392 __throw_exception_again;
398 template<typename _CharT, typename _Traits>
399 basic_istream<_CharT, _Traits>&
400 basic_istream<_CharT, _Traits>::
401 operator>>(double& __n)
403 sentry __cerb(*this, false);
408 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
409 const __num_get_type& __ng = __check_facet(this->_M_num_get);
410 __ng.get(*this, 0, *this, __err, __n);
411 this->setstate(__err);
415 // 27.6.1.2.1 Common requirements.
416 // Turn this on without causing an ios::failure to be thrown.
417 this->_M_setstate(ios_base::badbit);
418 if ((this->exceptions() & ios_base::badbit) != 0)
419 __throw_exception_again;
425 template<typename _CharT, typename _Traits>
426 basic_istream<_CharT, _Traits>&
427 basic_istream<_CharT, _Traits>::
428 operator>>(long double& __n)
430 sentry __cerb(*this, false);
435 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
436 const __num_get_type& __ng = __check_facet(this->_M_num_get);
437 __ng.get(*this, 0, *this, __err, __n);
438 this->setstate(__err);
442 // 27.6.1.2.1 Common requirements.
443 // Turn this on without causing an ios::failure to be thrown.
444 this->_M_setstate(ios_base::badbit);
445 if ((this->exceptions() & ios_base::badbit) != 0)
446 __throw_exception_again;
452 template<typename _CharT, typename _Traits>
453 basic_istream<_CharT, _Traits>&
454 basic_istream<_CharT, _Traits>::
455 operator>>(void*& __n)
457 sentry __cerb(*this, false);
462 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
463 const __num_get_type& __ng = __check_facet(this->_M_num_get);
464 __ng.get(*this, 0, *this, __err, __n);
465 this->setstate(__err);
469 // 27.6.1.2.1 Common requirements.
470 // Turn this on without causing an ios::failure to be thrown.
471 this->_M_setstate(ios_base::badbit);
472 if ((this->exceptions() & ios_base::badbit) != 0)
473 __throw_exception_again;
479 template<typename _CharT, typename _Traits>
480 basic_istream<_CharT, _Traits>&
481 basic_istream<_CharT, _Traits>::
482 operator>>(__streambuf_type* __sbout)
484 sentry __cerb(*this, false);
489 streamsize __xtrct = 0;
492 __streambuf_type* __sbin = this->rdbuf();
493 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
495 if (!__sbout || !__xtrct)
496 this->setstate(ios_base::failbit);
500 // 27.6.2.5.1 Common requirements.
501 // Turn this on without causing an ios::failure to be thrown.
502 this->_M_setstate(ios_base::badbit);
503 if ((this->exceptions() & ios_base::badbit) != 0)
504 __throw_exception_again;
510 template<typename _CharT, typename _Traits>
511 typename basic_istream<_CharT, _Traits>::int_type
512 basic_istream<_CharT, _Traits>::
515 const int_type __eof = traits_type::eof();
516 int_type __c = __eof;
518 sentry __cerb(*this, true);
523 __c = this->rdbuf()->sbumpc();
524 // 27.6.1.1 paragraph 3
525 if (!traits_type::eq_int_type(__c, __eof))
528 this->setstate(ios_base::eofbit | ios_base::failbit);
532 // 27.6.1.3 paragraph 1
533 // Turn this on without causing an ios::failure to be thrown.
534 this->_M_setstate(ios_base::badbit);
535 if ((this->exceptions() & ios_base::badbit) != 0)
536 __throw_exception_again;
542 template<typename _CharT, typename _Traits>
543 basic_istream<_CharT, _Traits>&
544 basic_istream<_CharT, _Traits>::
548 sentry __cerb(*this, true);
553 const int_type __eof = traits_type::eof();
554 int_type __bufval = this->rdbuf()->sbumpc();
555 // 27.6.1.1 paragraph 3
556 if (!traits_type::eq_int_type(__bufval, __eof))
559 __c = traits_type::to_char_type(__bufval);
562 this->setstate(ios_base::eofbit | ios_base::failbit);
566 // 27.6.1.3 paragraph 1
567 // Turn this on without causing an ios::failure to be thrown.
568 this->_M_setstate(ios_base::badbit);
569 if ((this->exceptions() & ios_base::badbit) != 0)
570 __throw_exception_again;
576 template<typename _CharT, typename _Traits>
577 basic_istream<_CharT, _Traits>&
578 basic_istream<_CharT, _Traits>::
579 get(char_type* __s, streamsize __n, char_type __delim)
582 sentry __cerb(*this, true);
587 const int_type __idelim = traits_type::to_int_type(__delim);
588 const int_type __eof = traits_type::eof();
589 __streambuf_type* __sb = this->rdbuf();
590 int_type __c = __sb->sgetc();
592 while (_M_gcount + 1 < __n
593 && !traits_type::eq_int_type(__c, __eof)
594 && !traits_type::eq_int_type(__c, __idelim))
596 *__s++ = traits_type::to_char_type(__c);
597 __c = __sb->snextc();
600 if (traits_type::eq_int_type(__c, __eof))
601 this->setstate(ios_base::eofbit);
605 // 27.6.1.3 paragraph 1
606 // Turn this on without causing an ios::failure to be thrown.
607 this->_M_setstate(ios_base::badbit);
608 if ((this->exceptions() & ios_base::badbit) != 0)
609 __throw_exception_again;
614 this->setstate(ios_base::failbit);
618 template<typename _CharT, typename _Traits>
619 basic_istream<_CharT, _Traits>&
620 basic_istream<_CharT, _Traits>::
621 get(__streambuf_type& __sb, char_type __delim)
624 sentry __cerb(*this, true);
629 const int_type __idelim = traits_type::to_int_type(__delim);
630 const int_type __eof = traits_type::eof();
631 __streambuf_type* __this_sb = this->rdbuf();
632 int_type __c = __this_sb->sgetc();
633 char_type __c2 = traits_type::to_char_type(__c);
635 while (!traits_type::eq_int_type(__c, __eof)
636 && !traits_type::eq_int_type(__c, __idelim)
637 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
640 __c = __this_sb->snextc();
641 __c2 = traits_type::to_char_type(__c);
643 if (traits_type::eq_int_type(__c, __eof))
644 this->setstate(ios_base::eofbit);
648 // 27.6.1.3 paragraph 1
649 // Turn this on without causing an ios::failure to be thrown.
650 this->_M_setstate(ios_base::badbit);
651 if ((this->exceptions() & ios_base::badbit) != 0)
652 __throw_exception_again;
656 this->setstate(ios_base::failbit);
660 template<typename _CharT, typename _Traits>
661 basic_istream<_CharT, _Traits>&
662 basic_istream<_CharT, _Traits>::
663 getline(char_type* __s, streamsize __n, char_type __delim)
666 sentry __cerb(*this, true);
671 const int_type __idelim = traits_type::to_int_type(__delim);
672 const int_type __eof = traits_type::eof();
673 __streambuf_type* __sb = this->rdbuf();
674 int_type __c = __sb->sgetc();
676 while (_M_gcount + 1 < __n
677 && !traits_type::eq_int_type(__c, __eof)
678 && !traits_type::eq_int_type(__c, __idelim))
680 *__s++ = traits_type::to_char_type(__c);
681 __c = __sb->snextc();
684 if (traits_type::eq_int_type(__c, __eof))
685 this->setstate(ios_base::eofbit);
688 if (traits_type::eq_int_type(__c, __idelim))
694 this->setstate(ios_base::failbit);
699 // 27.6.1.3 paragraph 1
700 // Turn this on without causing an ios::failure to be thrown.
701 this->_M_setstate(ios_base::badbit);
702 if ((this->exceptions() & ios_base::badbit) != 0)
703 __throw_exception_again;
708 this->setstate(ios_base::failbit);
712 template<typename _CharT, typename _Traits>
713 basic_istream<_CharT, _Traits>&
714 basic_istream<_CharT, _Traits>::
715 ignore(streamsize __n, int_type __delim)
718 sentry __cerb(*this, true);
719 if (__cerb && __n > 0)
723 const int_type __eof = traits_type::eof();
724 __streambuf_type* __sb = this->rdbuf();
727 __n = std::min(__n, numeric_limits<streamsize>::max());
728 while (_M_gcount < __n
729 && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
732 if (traits_type::eq_int_type(__c, __delim))
735 if (traits_type::eq_int_type(__c, __eof))
736 this->setstate(ios_base::eofbit);
740 // 27.6.1.3 paragraph 1
741 // Turn this on without causing an ios::failure to be thrown.
742 this->_M_setstate(ios_base::badbit);
743 if ((this->exceptions() & ios_base::badbit) != 0)
744 __throw_exception_again;
750 template<typename _CharT, typename _Traits>
751 typename basic_istream<_CharT, _Traits>::int_type
752 basic_istream<_CharT, _Traits>::
755 int_type __c = traits_type::eof();
757 sentry __cerb(*this, true);
762 __c = this->rdbuf()->sgetc();
763 if (traits_type::eq_int_type(__c, traits_type::eof()))
764 this->setstate(ios_base::eofbit);
768 // 27.6.1.3 paragraph 1
769 // Turn this on without causing an ios::failure to be thrown.
770 this->_M_setstate(ios_base::badbit);
771 if ((this->exceptions() & ios_base::badbit) != 0)
772 __throw_exception_again;
778 template<typename _CharT, typename _Traits>
779 basic_istream<_CharT, _Traits>&
780 basic_istream<_CharT, _Traits>::
781 read(char_type* __s, streamsize __n)
784 sentry __cerb(*this, true);
789 _M_gcount = this->rdbuf()->sgetn(__s, __n);
790 if (_M_gcount != __n)
791 this->setstate(ios_base::eofbit | ios_base::failbit);
795 // 27.6.1.3 paragraph 1
796 // Turn this on without causing an ios::failure to be thrown.
797 this->_M_setstate(ios_base::badbit);
798 if ((this->exceptions() & ios_base::badbit) != 0)
799 __throw_exception_again;
805 template<typename _CharT, typename _Traits>
807 basic_istream<_CharT, _Traits>::
808 readsome(char_type* __s, streamsize __n)
811 sentry __cerb(*this, true);
816 // Cannot compare int_type with streamsize generically.
817 streamsize __num = this->rdbuf()->in_avail();
820 __num = std::min(__num, __n);
822 _M_gcount = this->rdbuf()->sgetn(__s, __num);
825 this->setstate(ios_base::eofbit);
829 // 27.6.1.3 paragraph 1
830 // Turn this on without causing an ios::failure to be thrown.
831 this->_M_setstate(ios_base::badbit);
832 if ((this->exceptions() & ios_base::badbit) != 0)
833 __throw_exception_again;
839 template<typename _CharT, typename _Traits>
840 basic_istream<_CharT, _Traits>&
841 basic_istream<_CharT, _Traits>::
842 putback(char_type __c)
844 // _GLIBCXX_RESOLVE_LIB_DEFECTS
845 // 60. What is a formatted input function?
847 sentry __cerb(*this, true);
852 const int_type __eof = traits_type::eof();
853 __streambuf_type* __sb = this->rdbuf();
855 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
856 this->setstate(ios_base::badbit);
860 // 27.6.1.3 paragraph 1
861 // Turn this on without causing an ios::failure to be thrown.
862 this->_M_setstate(ios_base::badbit);
863 if ((this->exceptions() & ios_base::badbit) != 0)
864 __throw_exception_again;
870 template<typename _CharT, typename _Traits>
871 basic_istream<_CharT, _Traits>&
872 basic_istream<_CharT, _Traits>::
875 // _GLIBCXX_RESOLVE_LIB_DEFECTS
876 // 60. What is a formatted input function?
878 sentry __cerb(*this, true);
883 const int_type __eof = traits_type::eof();
884 __streambuf_type* __sb = this->rdbuf();
886 || traits_type::eq_int_type(__sb->sungetc(), __eof))
887 this->setstate(ios_base::badbit);
891 // 27.6.1.3 paragraph 1
892 // Turn this on without causing an ios::failure to be thrown.
893 this->_M_setstate(ios_base::badbit);
894 if ((this->exceptions() & ios_base::badbit) != 0)
895 __throw_exception_again;
901 template<typename _CharT, typename _Traits>
903 basic_istream<_CharT, _Traits>::
906 // DR60. Do not change _M_gcount.
908 sentry __cerb(*this, true);
913 __streambuf_type* __sb = this->rdbuf();
916 if (__sb->pubsync() == -1)
917 this->setstate(ios_base::badbit);
924 // 27.6.1.3 paragraph 1
925 // Turn this on without causing an ios::failure to be thrown.
926 this->_M_setstate(ios_base::badbit);
927 if ((this->exceptions() & ios_base::badbit) != 0)
928 __throw_exception_again;
934 template<typename _CharT, typename _Traits>
935 typename basic_istream<_CharT, _Traits>::pos_type
936 basic_istream<_CharT, _Traits>::
939 // DR60. Do not change _M_gcount.
940 pos_type __ret = pos_type(-1);
942 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
947 template<typename _CharT, typename _Traits>
948 basic_istream<_CharT, _Traits>&
949 basic_istream<_CharT, _Traits>::
950 seekg(pos_type __pos)
952 // DR60. Do not change _M_gcount.
955 // _GLIBCXX_RESOLVE_LIB_DEFECTS
956 // 136. seekp, seekg setting wrong streams?
957 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
959 // 129. Need error indication from seekp() and seekg()
960 if (__err == pos_type(off_type(-1)))
961 this->setstate(ios_base::failbit);
966 template<typename _CharT, typename _Traits>
967 basic_istream<_CharT, _Traits>&
968 basic_istream<_CharT, _Traits>::
969 seekg(off_type __off, ios_base::seekdir __dir)
971 // DR60. Do not change _M_gcount.
974 // _GLIBCXX_RESOLVE_LIB_DEFECTS
975 // 136. seekp, seekg setting wrong streams?
976 pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
979 // 129. Need error indication from seekp() and seekg()
980 if (__err == pos_type(off_type(-1)))
981 this->setstate(ios_base::failbit);
986 // 27.6.1.2.3 Character extraction templates
987 template<typename _CharT, typename _Traits>
988 basic_istream<_CharT, _Traits>&
989 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
991 typedef basic_istream<_CharT, _Traits> __istream_type;
992 typename __istream_type::sentry __cerb(__in, false);
999 // 27.6.1.2.1 Common requirements.
1000 // Turn this on without causing an ios::failure to be thrown.
1001 __in._M_setstate(ios_base::badbit);
1002 if ((__in.exceptions() & ios_base::badbit) != 0)
1003 __throw_exception_again;
1009 template<typename _CharT, typename _Traits>
1010 basic_istream<_CharT, _Traits>&
1011 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1013 typedef basic_istream<_CharT, _Traits> __istream_type;
1014 typedef typename __istream_type::__streambuf_type __streambuf_type;
1015 typedef typename _Traits::int_type int_type;
1016 typedef _CharT char_type;
1017 typedef ctype<_CharT> __ctype_type;
1018 streamsize __extracted = 0;
1020 typename __istream_type::sentry __cerb(__in, false);
1025 // Figure out how many characters to extract.
1026 streamsize __num = __in.width();
1028 __num = numeric_limits<streamsize>::max();
1030 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1032 const int_type __eof = _Traits::eof();
1033 __streambuf_type* __sb = __in.rdbuf();
1034 int_type __c = __sb->sgetc();
1036 while (__extracted < __num - 1
1037 && !_Traits::eq_int_type(__c, __eof)
1038 && !__ct.is(ctype_base::space,
1039 _Traits::to_char_type(__c)))
1041 *__s++ = _Traits::to_char_type(__c);
1043 __c = __sb->snextc();
1045 if (_Traits::eq_int_type(__c, __eof))
1046 __in.setstate(ios_base::eofbit);
1048 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1049 // 68. Extractors for char* should store null at end
1055 // 27.6.1.2.1 Common requirements.
1056 // Turn this on without causing an ios::failure to be thrown.
1057 __in._M_setstate(ios_base::badbit);
1058 if ((__in.exceptions() & ios_base::badbit) != 0)
1059 __throw_exception_again;
1063 __in.setstate(ios_base::failbit);
1067 // 27.6.1.4 Standard basic_istream manipulators
1068 template<typename _CharT, typename _Traits>
1069 basic_istream<_CharT,_Traits>&
1070 ws(basic_istream<_CharT,_Traits>& __in)
1072 typedef basic_istream<_CharT, _Traits> __istream_type;
1073 typedef typename __istream_type::__streambuf_type __streambuf_type;
1074 typedef typename __istream_type::__ctype_type __ctype_type;
1075 typedef typename __istream_type::int_type __int_type;
1077 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1078 const __int_type __eof = _Traits::eof();
1079 __streambuf_type* __sb = __in.rdbuf();
1080 __int_type __c = __sb->sgetc();
1082 while (!_Traits::eq_int_type(__c, __eof)
1083 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1084 __c = __sb->snextc();
1086 if (_Traits::eq_int_type(__c, __eof))
1087 __in.setstate(ios_base::eofbit);
1092 // 21.3.7.9 basic_string::getline and operators
1093 template<typename _CharT, typename _Traits, typename _Alloc>
1094 basic_istream<_CharT, _Traits>&
1095 operator>>(basic_istream<_CharT, _Traits>& __in,
1096 basic_string<_CharT, _Traits, _Alloc>& __str)
1098 typedef basic_istream<_CharT, _Traits> __istream_type;
1099 typedef typename __istream_type::int_type __int_type;
1100 typedef typename __istream_type::__streambuf_type __streambuf_type;
1101 typedef typename __istream_type::__ctype_type __ctype_type;
1102 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1103 typedef typename __string_type::size_type __size_type;
1104 __size_type __extracted = 0;
1106 typename __istream_type::sentry __cerb(__in, false);
1110 streamsize __w = __in.width();
1112 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1114 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1115 const __int_type __eof = _Traits::eof();
1116 __streambuf_type* __sb = __in.rdbuf();
1117 __int_type __c = __sb->sgetc();
1119 while (__extracted < __n
1120 && !_Traits::eq_int_type(__c, __eof)
1121 && !__ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1123 __str += _Traits::to_char_type(__c);
1125 __c = __sb->snextc();
1127 if (_Traits::eq_int_type(__c, __eof))
1128 __in.setstate(ios_base::eofbit);
1131 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1132 // 211. operator>>(istream&, string&) doesn't set failbit
1134 __in.setstate (ios_base::failbit);
1138 template<typename _CharT, typename _Traits, typename _Alloc>
1139 basic_istream<_CharT, _Traits>&
1140 getline(basic_istream<_CharT, _Traits>& __in,
1141 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1143 typedef basic_istream<_CharT, _Traits> __istream_type;
1144 typedef typename __istream_type::int_type __int_type;
1145 typedef typename __istream_type::__streambuf_type __streambuf_type;
1146 typedef typename __istream_type::__ctype_type __ctype_type;
1147 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1148 typedef typename __string_type::size_type __size_type;
1150 __size_type __extracted = 0;
1151 bool __testdelim = false;
1152 typename __istream_type::sentry __cerb(__in, true);
1156 __size_type __n = __str.max_size();
1158 __int_type __idelim = _Traits::to_int_type(__delim);
1159 __streambuf_type* __sb = __in.rdbuf();
1160 __int_type __c = __sb->sbumpc();
1161 const __int_type __eof = _Traits::eof();
1162 __testdelim = _Traits::eq_int_type(__c, __idelim);
1164 while (__extracted <= __n && !_Traits::eq_int_type(__c, __eof)
1167 __str += _Traits::to_char_type(__c);
1169 __c = __sb->sbumpc();
1170 __testdelim = _Traits::eq_int_type(__c, __idelim);
1172 if (_Traits::eq_int_type(__c, __eof))
1173 __in.setstate(ios_base::eofbit);
1175 if (!__extracted && !__testdelim)
1176 __in.setstate(ios_base::failbit);
1180 template<class _CharT, class _Traits, class _Alloc>
1181 inline basic_istream<_CharT,_Traits>&
1182 getline(basic_istream<_CharT, _Traits>& __in,
1183 basic_string<_CharT,_Traits,_Alloc>& __str)
1184 { return getline(__in, __str, __in.widen('\n')); }
1186 // Inhibit implicit instantiations for required instantiations,
1187 // which are defined via explicit instantiations elsewhere.
1188 // NB: This syntax is a GNU extension.
1189 #if _GLIBCXX_EXTERN_TEMPLATE
1190 extern template class basic_istream<char>;
1191 extern template istream& ws(istream&);
1192 extern template istream& operator>>(istream&, char&);
1193 extern template istream& operator>>(istream&, char*);
1194 extern template istream& operator>>(istream&, unsigned char&);
1195 extern template istream& operator>>(istream&, signed char&);
1196 extern template istream& operator>>(istream&, unsigned char*);
1197 extern template istream& operator>>(istream&, signed char*);
1199 #ifdef _GLIBCXX_USE_WCHAR_T
1200 extern template class basic_istream<wchar_t>;
1201 extern template wistream& ws(wistream&);
1202 extern template wistream& operator>>(wistream&, wchar_t&);
1203 extern template wistream& operator>>(wistream&, wchar_t*);