1 // Input streams -*- C++ -*-
3 // Copyright (C) 1997-2026 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
26 // ISO C++ 14882: 27.6.1 Input streams
29 /** @file include/istream
30 * This is a Standard C++ Library header.
33 #ifndef _GLIBCXX_ISTREAM
34 #define _GLIBCXX_ISTREAM 1
36 #ifdef _GLIBCXX_SYSHDR
37 #pragma GCC system_header
40 #include <bits/requires_hosted.h> // iostreams
45 #if __cplusplus > 202302L
49 namespace std _GLIBCXX_VISIBILITY(default)
51 _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 * @brief Template class basic_istream.
57 * @tparam _CharT Type of character stream.
58 * @tparam _Traits Traits for character type, defaults to
59 * char_traits<_CharT>.
61 * This is the base class for all input streams. It provides text
62 * formatting of all builtin types, and communicates with any class
63 * derived from basic_streambuf to do the actual input.
65 template<typename _CharT, typename _Traits>
66 class basic_istream : virtual public basic_ios<_CharT, _Traits>
69 // Types (inherited from basic_ios (27.4.4)):
70 typedef _CharT char_type;
71 typedef typename _Traits::int_type int_type;
72 typedef typename _Traits::pos_type pos_type;
73 typedef typename _Traits::off_type off_type;
74 typedef _Traits traits_type;
76 // Non-standard Types:
77 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
78 typedef basic_ios<_CharT, _Traits> __ios_type;
79 typedef basic_istream<_CharT, _Traits> __istream_type;
80 typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
82 typedef ctype<_CharT> __ctype_type;
87 * The number of characters extracted in the previous unformatted
88 * function; see gcount().
94 * @brief Base constructor.
96 * This ctor is almost never called by the user directly, rather from
97 * derived classes' initialization lists, which pass a pointer to
98 * their own stream buffer.
101 basic_istream(__streambuf_type* __sb)
102 : _M_gcount(streamsize(0))
103 { this->init(__sb); }
106 * @brief Base destructor.
108 * This does very little apart from providing a virtual base dtor.
112 { _M_gcount = streamsize(0); }
114 /// Safe prefix/suffix operations.
120 * @brief Interface for manipulators.
122 * Manipulators such as @c std::ws and @c std::dec use these
123 * functions in constructs like
124 * <code>std::cin >> std::ws</code>.
125 * For more information, see the iomanip header.
128 operator>>(__istream_type& (*__pf)(__istream_type&))
129 { return __pf(*this); }
132 operator>>(__ios_type& (*__pf)(__ios_type&))
139 operator>>(ios_base& (*__pf)(ios_base&))
150 * All the @c operator>> functions (aka <em>formatted input
151 * functions</em>) have some common behavior. Each starts by
152 * constructing a temporary object of type std::basic_istream::sentry
153 * with the second argument (noskipws) set to false. This has several
154 * effects, concluding with the setting of a status flag; see the
155 * sentry documentation for more.
157 * If the sentry status is good, the function tries to extract
158 * whatever data is appropriate for the type of the argument.
160 * If an exception is thrown during extraction, ios_base::badbit
161 * will be turned on in the stream's error state (without causing an
162 * ios_base::failure to be thrown) and the original exception will
163 * be rethrown if badbit is set in the exceptions mask.
168 * @brief Integer arithmetic extractors
169 * @param __n A variable of builtin integral type.
170 * @return @c *this if successful
172 * These functions use the stream's current locale (specifically, the
173 * @c num_get facet) to parse the input data.
176 operator>>(bool& __n)
177 { return _M_extract(__n); }
180 operator>>(short& __n);
183 operator>>(unsigned short& __n)
184 { return _M_extract(__n); }
187 operator>>(int& __n);
190 operator>>(unsigned int& __n)
191 { return _M_extract(__n); }
194 operator>>(long& __n)
195 { return _M_extract(__n); }
198 operator>>(unsigned long& __n)
199 { return _M_extract(__n); }
201 #ifdef _GLIBCXX_USE_LONG_LONG
202 #pragma GCC diagnostic push
203 #pragma GCC diagnostic ignored "-Wlong-long"
205 operator>>(long long& __n)
206 { return _M_extract(__n); }
209 operator>>(unsigned long long& __n)
210 { return _M_extract(__n); }
211 #pragma GCC diagnostic pop
217 * @brief Floating point arithmetic extractors
218 * @param __f A variable of builtin floating point type.
219 * @return @c *this if successful
221 * These functions use the stream's current locale (specifically, the
222 * @c num_get facet) to parse the input data.
225 operator>>(float& __f)
226 { return _M_extract(__f); }
229 operator>>(double& __f)
230 { return _M_extract(__f); }
233 operator>>(long double& __f)
234 { return _M_extract(__f); }
237 #if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
238 __attribute__((__always_inline__))
240 operator>>(_Float16& __f)
243 __istream_type& __ret = _M_extract(__flt);
244 ios_base::iostate __err = ios_base::goodbit;
245 if (__flt < -__FLT16_MAX__)
247 __f = -__FLT16_MAX__;
248 __err = ios_base::failbit;
250 else if (__flt > __FLT16_MAX__)
253 __err = ios_base::failbit;
256 __f = static_cast<_Float16>(__flt);
258 this->setstate(__err);
263 #if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
264 __attribute__((__always_inline__))
266 operator>>(_Float32& __f)
269 __istream_type& __ret = _M_extract(__flt);
270 __f = static_cast<_Float32> (__flt);
275 #if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
276 __attribute__((__always_inline__))
278 operator>>(_Float64& __f)
281 __istream_type& __ret = _M_extract(__dbl);
282 __f = static_cast<_Float64> (__dbl);
287 #if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
288 __attribute__((__always_inline__))
290 operator>>(_Float128& __f)
293 __istream_type& __ret = _M_extract(__ldbl);
294 __f = static_cast<_Float128> (__ldbl);
299 #if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
300 __attribute__((__always_inline__))
302 operator>>(__gnu_cxx::__bfloat16_t & __f)
305 __istream_type& __ret = _M_extract(__flt);
306 ios_base::iostate __err = ios_base::goodbit;
307 if (__flt < -__BFLT16_MAX__)
309 __f = -__BFLT16_MAX__;
310 __err = ios_base::failbit;
312 else if (__flt > __BFLT16_MAX__)
314 __f = __BFLT16_MAX__;
315 __err = ios_base::failbit;
318 __f = static_cast<__gnu_cxx::__bfloat16_t>(__flt);
320 this->setstate(__err);
326 * @brief Basic arithmetic extractors
327 * @param __p A variable of pointer type.
328 * @return @c *this if successful
330 * These functions use the stream's current locale (specifically, the
331 * @c num_get facet) to parse the input data.
334 operator>>(void*& __p)
335 { return _M_extract(__p); }
338 * @brief Extracting into another streambuf.
339 * @param __sb A pointer to a streambuf
341 * This function behaves like one of the basic arithmetic extractors,
342 * in that it also constructs a sentry object and has the same error
345 * If @p __sb is NULL, the stream will set failbit in its error state.
347 * Characters are extracted from this stream and inserted into the
348 * @p __sb streambuf until one of the following occurs:
350 * - the input stream reaches end-of-file,
351 * - insertion into the output buffer fails (in this case, the
352 * character that would have been inserted is not extracted), or
353 * - an exception occurs (and in this case is caught)
355 * If the function inserts no characters, failbit is set.
358 operator>>(__streambuf_type* __sb);
361 // [27.6.1.3] unformatted input
363 * @brief Character counting
364 * @return The number of characters extracted by the previous
365 * unformatted input function dispatched for this stream.
369 { return _M_gcount; }
373 * @name Unformatted Input Functions
375 * All the unformatted input functions have some common behavior.
376 * Each starts by constructing a temporary object of type
377 * std::basic_istream::sentry with the second argument (noskipws)
378 * set to true. This has several effects, concluding with the
379 * setting of a status flag; see the sentry documentation for more.
381 * If the sentry status is good, the function tries to extract
382 * whatever data is appropriate for the type of the argument.
384 * The number of characters extracted is stored for later retrieval
387 * If an exception is thrown during extraction, ios_base::badbit
388 * will be turned on in the stream's error state (without causing an
389 * ios_base::failure to be thrown) and the original exception will
390 * be rethrown if badbit is set in the exceptions mask.
394 * @brief Simple extraction.
395 * @return A character, or eof().
397 * Tries to extract a character. If none are available, sets failbit
398 * and returns traits::eof().
404 * @brief Simple extraction.
405 * @param __c The character in which to store data.
408 * Tries to extract a character and store it in @a __c. If none are
409 * available, sets failbit and returns traits::eof().
411 * @note This function is not overloaded on signed char and
418 * @brief Simple multiple-character extraction.
419 * @param __s Pointer to an array.
420 * @param __n Maximum number of characters to store in @a __s.
421 * @param __delim A "stop" character.
424 * Characters are extracted and stored into @a __s until one of the
427 * - @c __n-1 characters are stored
428 * - the input sequence reaches EOF
429 * - the next character equals @a __delim, in which case the character
432 * If no characters are stored, failbit is set in the stream's error
435 * In any case, a null character is stored into the next location in
438 * @note This function is not overloaded on signed char and
442 get(char_type* __s, streamsize __n, char_type __delim);
445 * @brief Simple multiple-character extraction.
446 * @param __s Pointer to an array.
447 * @param __n Maximum number of characters to store in @a s.
450 * Returns @c get(__s,__n,widen('\\n')).
453 get(char_type* __s, streamsize __n)
454 { return this->get(__s, __n, this->widen('\n')); }
457 * @brief Extraction into another streambuf.
458 * @param __sb A streambuf in which to store data.
459 * @param __delim A "stop" character.
462 * Characters are extracted and inserted into @a __sb until one of the
465 * - the input sequence reaches EOF
466 * - insertion into the output buffer fails (in this case, the
467 * character that would have been inserted is not extracted)
468 * - the next character equals @a __delim (in this case, the character
470 * - an exception occurs (and in this case is caught)
472 * If no characters are stored, failbit is set in the stream's error
476 get(__streambuf_type& __sb, char_type __delim);
479 * @brief Extraction into another streambuf.
480 * @param __sb A streambuf in which to store data.
483 * Returns @c get(__sb,widen('\\n')).
486 get(__streambuf_type& __sb)
487 { return this->get(__sb, this->widen('\n')); }
490 * @brief String extraction.
491 * @param __s A character array in which to store the data.
492 * @param __n Maximum number of characters to extract.
493 * @param __delim A "stop" character.
496 * Extracts and stores characters into @a __s until one of the
497 * following happens. Note that these criteria are required to be
498 * tested in the order listed here, to allow an input line to exactly
499 * fill the @a __s array without setting failbit.
501 * -# the input sequence reaches end-of-file, in which case eofbit
502 * is set in the stream error state
503 * -# the next character equals @c __delim, in which case the character
504 * is extracted (and therefore counted in @c gcount()) but not stored
505 * -# @c __n-1 characters are stored, in which case failbit is set
506 * in the stream error state
508 * If no characters are extracted, failbit is set. (An empty line of
509 * input should therefore not cause failbit to be set.)
511 * In any case, a null character is stored in the next location in
515 getline(char_type* __s, streamsize __n, char_type __delim);
518 * @brief String extraction.
519 * @param __s A character array in which to store the data.
520 * @param __n Maximum number of characters to extract.
523 * Returns @c getline(__s,__n,widen('\\n')).
526 getline(char_type* __s, streamsize __n)
527 { return this->getline(__s, __n, this->widen('\n')); }
530 * @brief Discarding characters
531 * @param __n Number of characters to discard.
532 * @param __delim A "stop" character.
535 * Extracts characters and throws them away until one of the
537 * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
538 * characters are extracted
539 * - the input sequence reaches end-of-file
540 * - the next character equals @a __delim (in this case, the character
541 * is extracted); note that this condition will never occur if
542 * @a __delim equals @c traits::eof().
544 * NB: Provide four overloads, instead of the single function
545 * (with defaults) mandated by the Standard: this leads to a
546 * better performing implementation, while still conforming to
550 ignore(streamsize __n, int_type __delim);
553 ignore(streamsize __n);
558 #if __cplusplus > 202302L
559 [[__gnu__::__always_inline__]]
561 ignore(streamsize __n, char __delim) requires same_as<_CharT, char>
562 { return ignore(__n, traits_type::to_int_type(__delim)); }
566 * @brief Looking ahead in the stream
567 * @return The next character, or eof().
569 * If, after constructing the sentry object, @c good() is false,
570 * returns @c traits::eof(). Otherwise reads but does not extract
571 * the next input character.
577 * @brief Extraction without delimiters.
578 * @param __s A character array.
579 * @param __n Maximum number of characters to store.
582 * If the stream state is @c good(), extracts characters and stores
583 * them into @a __s until one of the following happens:
584 * - @a __n characters are stored
585 * - the input sequence reaches end-of-file, in which case the error
586 * state is set to @c failbit|eofbit.
588 * @note This function is not overloaded on signed char and
592 read(char_type* __s, streamsize __n);
595 * @brief Extraction until the buffer is exhausted, but no more.
596 * @param __s A character array.
597 * @param __n Maximum number of characters to store.
598 * @return The number of characters extracted.
600 * Extracts characters and stores them into @a __s depending on the
601 * number of characters remaining in the streambuf's buffer,
602 * @c rdbuf()->in_avail(), called @c A here:
603 * - if @c A @c == @c -1, sets eofbit and extracts no characters
604 * - if @c A @c == @c 0, extracts no characters
605 * - if @c A @c > @c 0, extracts @c min(A,n)
607 * The goal is to empty the current buffer, and to not request any
608 * more from the external input sequence controlled by the streambuf.
611 readsome(char_type* __s, streamsize __n);
614 * @brief Unextracting a single character.
615 * @param __c The character to push back into the input stream.
618 * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
620 * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
623 * @note This function first clears eofbit. Since no characters
624 * are extracted, the next call to @c gcount() will return 0,
625 * as required by DR 60.
628 putback(char_type __c);
631 * @brief Unextracting the previous character.
634 * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
636 * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
639 * @note This function first clears eofbit. Since no characters
640 * are extracted, the next call to @c gcount() will return 0,
641 * as required by DR 60.
647 * @brief Synchronizing the stream buffer.
648 * @return 0 on success, -1 on failure
650 * If @c rdbuf() is a null pointer, returns -1.
652 * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
653 * sets badbit and returns -1.
655 * Otherwise, returns 0.
657 * @note This function does not count the number of characters
658 * extracted, if any, and therefore does not affect the next
659 * call to @c gcount().
665 * @brief Getting the current read position.
666 * @return A file position object.
668 * If @c fail() is not false, returns @c pos_type(-1) to indicate
669 * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
671 * @note This function does not count the number of characters
672 * extracted, if any, and therefore does not affect the next
673 * call to @c gcount(). At variance with putback, unget and
674 * seekg, eofbit is not cleared first.
680 * @brief Changing the current read position.
681 * @param __pos A file position object.
684 * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If
685 * that function fails, sets failbit.
687 * @note This function first clears eofbit. It does not count the
688 * number of characters extracted, if any, and therefore does
689 * not affect the next call to @c gcount().
695 * @brief Changing the current read position.
696 * @param __off A file offset object.
697 * @param __dir The direction in which to seek.
700 * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
701 * If that function fails, sets failbit.
703 * @note This function first clears eofbit. It does not count the
704 * number of characters extracted, if any, and therefore does
705 * not affect the next call to @c gcount().
708 seekg(off_type, ios_base::seekdir);
713 : _M_gcount(streamsize(0))
716 #if __cplusplus >= 201103L
717 basic_istream(const basic_istream&) = delete;
719 basic_istream(basic_istream&& __rhs)
720 : __ios_type(), _M_gcount(__rhs._M_gcount)
722 __ios_type::move(__rhs);
726 // 27.7.3.3 Assign/swap
728 basic_istream& operator=(const basic_istream&) = delete;
731 operator=(basic_istream&& __rhs)
738 swap(basic_istream& __rhs)
740 __ios_type::swap(__rhs);
741 std::swap(_M_gcount, __rhs._M_gcount);
745 template<typename _ValueT>
747 _M_extract(_ValueT& __v);
750 /// Explicit specialization declarations, defined in src/istream.cc.
753 basic_istream<char>::
754 getline(char_type* __s, streamsize __n, char_type __delim);
758 basic_istream<char>::
759 ignore(streamsize __n);
763 basic_istream<char>::
764 ignore(streamsize __n, int_type __delim);
766 #ifdef _GLIBCXX_USE_WCHAR_T
768 basic_istream<wchar_t>&
769 basic_istream<wchar_t>::
770 getline(char_type* __s, streamsize __n, char_type __delim);
773 basic_istream<wchar_t>&
774 basic_istream<wchar_t>::
775 ignore(streamsize __n);
778 basic_istream<wchar_t>&
779 basic_istream<wchar_t>::
780 ignore(streamsize __n, int_type __delim);
784 * @brief Performs setup work for input streams.
786 * Objects of this class are created before all of the standard
787 * extractors are run. It is responsible for <em>exception-safe
788 * prefix and suffix operations,</em> although only prefix actions
789 * are currently required by the standard.
791 template<typename _CharT, typename _Traits>
792 class basic_istream<_CharT, _Traits>::sentry
798 /// Easy access to dependent types.
799 typedef _Traits traits_type;
800 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
801 typedef basic_istream<_CharT, _Traits> __istream_type;
802 typedef typename __istream_type::__ctype_type __ctype_type;
803 typedef typename _Traits::int_type __int_type;
806 * @brief The constructor performs all the work.
807 * @param __is The input stream to guard.
808 * @param __noskipws Whether to consume whitespace or not.
810 * If the stream state is good (@a __is.good() is true), then the
811 * following actions are performed, otherwise the sentry state
812 * is false (<em>not okay</em>) and failbit is set in the
815 * The sentry's preparatory actions are:
817 * -# if the stream is tied to an output stream, @c is.tie()->flush()
818 * is called to synchronize the output sequence
819 * -# if @a __noskipws is false, and @c ios_base::skipws is set in
820 * @c is.flags(), the sentry extracts and discards whitespace
821 * characters from the stream. The currently imbued locale is
822 * used to determine whether each character is whitespace.
824 * If the stream state is still good, then the sentry state becomes
828 sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
831 * @brief Quick status checking.
832 * @return The sentry state.
834 * For ease of use, sentries may be converted to booleans. The
835 * return value is that of the sentry state (true == okay).
837 #if __cplusplus >= 201103L
840 operator bool() const
846 * @brief Character extractors
847 * @param __in An input stream.
848 * @param __c A character reference.
851 * Behaves like one of the formatted arithmetic extractors described in
852 * std::basic_istream. After constructing a sentry object with good
853 * status, this function extracts a character (if one is available) and
854 * stores it in @a __c. Otherwise, sets failbit in the input stream.
856 template<typename _CharT, typename _Traits>
857 basic_istream<_CharT, _Traits>&
858 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
860 template<class _Traits>
861 inline basic_istream<char, _Traits>&
862 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
863 { return (__in >> reinterpret_cast<char&>(__c)); }
865 template<class _Traits>
866 inline basic_istream<char, _Traits>&
867 operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
868 { return (__in >> reinterpret_cast<char&>(__c)); }
872 template<typename _CharT, typename _Traits>
874 __istream_extract(basic_istream<_CharT, _Traits>&, _CharT*, streamsize);
876 void __istream_extract(istream&, char*, streamsize);
880 * @brief Character string extractors
881 * @param __in An input stream.
882 * @param __s A character array (or a pointer to an array before C++20).
885 * Behaves like one of the formatted arithmetic extractors described in
886 * `std::basic_istream`. After constructing a sentry object with good
887 * status, this function extracts up to `n` characters and stores them
888 * into the array `__s`. `n` is defined as:
890 * - if `width()` is greater than zero, `n` is `min(width(), n)`
891 * - otherwise `n` is the number of elements of the array
892 * - (before C++20 the pointer is assumed to point to an array of
893 * the largest possible size for an array of `char_type`).
895 * Characters are extracted and stored until one of the following happens:
896 * - `n - 1` characters are stored
898 * - the next character is whitespace according to the current locale
900 * `width(0)` is then called for the input stream.
902 * If no characters are extracted, sets failbit.
905 #if __cplusplus <= 201703L
906 template<typename _CharT, typename _Traits>
907 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
908 inline basic_istream<_CharT, _Traits>&
909 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
912 // Function inlining might make the buffer size known, allowing us to
914 size_t __n = __builtin_object_size(__s, 0);
915 if (__n < sizeof(_CharT))
917 // There is not even space for the required null terminator.
918 __glibcxx_assert(__n >= sizeof(_CharT));
919 // No point calling __istream_extract, but still need to reset width.
921 __in.setstate(ios_base::failbit);
923 else if (__n != (size_t)-1)
925 __n /= sizeof(_CharT);
926 streamsize __w = __in.width();
927 std::__istream_extract(__in, __s, __n);
928 if (__in.good() && (__w <= 0 || __n < (size_t)__w))
930 // Stopped extracting early to avoid overflowing the buffer,
931 // but might have stopped anyway (and set eofbit) if at EOF.
932 const typename _Traits::int_type __c = __in.rdbuf()->sgetc();
933 const bool __eof = _Traits::eq_int_type(__c, _Traits::eof());
934 if (__builtin_expect(__eof, true)) // Assume EOF, not overflow.
935 __in.setstate(ios_base::eofbit);
941 // Buffer size is unknown, have to assume it's huge.
942 streamsize __n = __gnu_cxx::__numeric_traits<streamsize>::__max;
943 __n /= sizeof(_CharT);
944 std::__istream_extract(__in, __s, __n);
949 template<class _Traits>
950 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
951 inline basic_istream<char, _Traits>&
952 operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
953 { return __in >> reinterpret_cast<char*>(__s); }
955 template<class _Traits>
956 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
957 inline basic_istream<char, _Traits>&
958 operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
959 { return __in >> reinterpret_cast<char*>(__s); }
961 // _GLIBCXX_RESOLVE_LIB_DEFECTS
962 // 2499. operator>>(istream&, char*) makes it hard to avoid buffer overflows
963 template<typename _CharT, typename _Traits, size_t _Num>
964 inline basic_istream<_CharT, _Traits>&
965 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT (&__s)[_Num])
967 static_assert(_Num <= __gnu_cxx::__numeric_traits<streamsize>::__max);
968 std::__istream_extract(__in, __s, _Num);
972 template<class _Traits, size_t _Num>
973 inline basic_istream<char, _Traits>&
974 operator>>(basic_istream<char, _Traits>& __in, unsigned char (&__s)[_Num])
975 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
977 template<class _Traits, size_t _Num>
978 inline basic_istream<char, _Traits>&
979 operator>>(basic_istream<char, _Traits>& __in, signed char (&__s)[_Num])
980 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
985 * @brief Template class basic_iostream
988 * @tparam _CharT Type of character stream.
989 * @tparam _Traits Traits for character type, defaults to
990 * char_traits<_CharT>.
992 * This class multiply inherits from the input and output stream classes
993 * simply to provide a single interface.
995 template<typename _CharT, typename _Traits>
997 : public basic_istream<_CharT, _Traits>,
998 public basic_ostream<_CharT, _Traits>
1001 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1002 // 271. basic_iostream missing typedefs
1003 // Types (inherited):
1004 typedef _CharT char_type;
1005 typedef typename _Traits::int_type int_type;
1006 typedef typename _Traits::pos_type pos_type;
1007 typedef typename _Traits::off_type off_type;
1008 typedef _Traits traits_type;
1010 // Non-standard Types:
1011 typedef basic_istream<_CharT, _Traits> __istream_type;
1012 typedef basic_ostream<_CharT, _Traits> __ostream_type;
1015 * @brief Constructor does nothing.
1017 * Both of the parent classes are initialized with the same
1018 * streambuf pointer passed to this constructor.
1021 basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
1022 : __istream_type(__sb), __ostream_type(__sb) { }
1025 * @brief Destructor does nothing.
1028 ~basic_iostream() { }
1032 : __istream_type(), __ostream_type() { }
1034 #if __cplusplus >= 201103L
1035 basic_iostream(const basic_iostream&) = delete;
1037 basic_iostream(basic_iostream&& __rhs)
1038 : __istream_type(std::move(__rhs)), __ostream_type(*this)
1041 // 27.7.3.3 Assign/swap
1043 basic_iostream& operator=(const basic_iostream&) = delete;
1046 operator=(basic_iostream&& __rhs)
1053 swap(basic_iostream& __rhs)
1054 { __istream_type::swap(__rhs); }
1059 * @brief Quick and easy way to eat whitespace
1061 * This manipulator extracts whitespace characters, stopping when the
1062 * next character is non-whitespace, or when the input sequence is empty.
1063 * If the sequence is empty, @c eofbit is set in the stream, but not
1066 * The current locale is used to distinguish whitespace characters.
1072 * std::cin >> std::ws >> mc;
1074 * will skip leading whitespace before calling operator>> on cin and your
1075 * object. Note that the same effect can be achieved by creating a
1076 * std::basic_istream::sentry inside your definition of operator>>.
1078 template<typename _CharT, typename _Traits>
1079 basic_istream<_CharT, _Traits>&
1080 ws(basic_istream<_CharT, _Traits>& __is);
1082 #if __cplusplus >= 201103L
1083 // C++11 27.7.2.6 Rvalue stream extraction [istream.rvalue]
1084 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1085 // 2328. Rvalue stream extraction should use perfect forwarding
1086 // 1203. More useful rvalue stream insertion
1088 #if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
1089 template<typename _Is, typename _Tp>
1090 requires __derived_from_ios_base<_Is>
1091 && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); }
1092 using __rvalue_stream_extraction_t = _Is&&;
1094 template<typename _Is, typename _Tp,
1095 typename = _Require_derived_from_ios_base<_Is>,
1096 typename = decltype(std::declval<_Is&>() >> std::declval<_Tp>())>
1097 using __rvalue_stream_extraction_t = _Is&&;
1101 * @brief Generic extractor for rvalue stream
1102 * @param __is An input stream.
1103 * @param __x A reference to the extraction target.
1106 * This is just a forwarding function to allow extraction from
1107 * rvalue streams since they won't bind to the extractor functions
1108 * that take an lvalue reference.
1110 template<typename _Istream, typename _Tp>
1111 inline __rvalue_stream_extraction_t<_Istream, _Tp>
1112 operator>>(_Istream&& __is, _Tp&& __x)
1114 __is >> std::forward<_Tp>(__x);
1115 return std::move(__is);
1119 _GLIBCXX_END_NAMESPACE_VERSION
1122 #include <bits/istream.tcc>
1124 #endif /* _GLIBCXX_ISTREAM */