1// Input streams -*- C++ -*-
3// Copyright (C) 1997-2025 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
37#pragma GCC system_header
40#include <bits/requires_hosted.h> // iostreams
45namespace std _GLIBCXX_VISIBILITY(default)
47_GLIBCXX_BEGIN_NAMESPACE_VERSION
50 * @brief Template class basic_istream.
53 * @tparam _CharT Type of character stream.
54 * @tparam _Traits Traits for character type, defaults to
55 * char_traits<_CharT>.
57 * This is the base class for all input streams. It provides text
58 * formatting of all builtin types, and communicates with any class
59 * derived from basic_streambuf to do the actual input.
61 template<typename _CharT, typename _Traits>
62 class basic_istream : virtual public basic_ios<_CharT, _Traits>
65 // Types (inherited from basic_ios (27.4.4)):
66 typedef _CharT char_type;
67 typedef typename _Traits::int_type int_type;
68 typedef typename _Traits::pos_type pos_type;
69 typedef typename _Traits::off_type off_type;
70 typedef _Traits traits_type;
72 // Non-standard Types:
73 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
74 typedef basic_ios<_CharT, _Traits> __ios_type;
75 typedef basic_istream<_CharT, _Traits> __istream_type;
76 typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
78 typedef ctype<_CharT> __ctype_type;
83 * The number of characters extracted in the previous unformatted
84 * function; see gcount().
90 * @brief Base constructor.
92 * This ctor is almost never called by the user directly, rather from
93 * derived classes' initialization lists, which pass a pointer to
94 * their own stream buffer.
97 basic_istream(__streambuf_type* __sb)
98 : _M_gcount(streamsize(0))
102 * @brief Base destructor.
104 * This does very little apart from providing a virtual base dtor.
108 { _M_gcount = streamsize(0); }
110 /// Safe prefix/suffix operations.
116 * @brief Interface for manipulators.
118 * Manipulators such as @c std::ws and @c std::dec use these
119 * functions in constructs like
120 * <code>std::cin >> std::ws</code>.
121 * For more information, see the iomanip header.
124 operator>>(__istream_type& (*__pf)(__istream_type&))
125 { return __pf(*this); }
128 operator>>(__ios_type& (*__pf)(__ios_type&))
135 operator>>(ios_base& (*__pf)(ios_base&))
146 * All the @c operator>> functions (aka <em>formatted input
147 * functions</em>) have some common behavior. Each starts by
148 * constructing a temporary object of type std::basic_istream::sentry
149 * with the second argument (noskipws) set to false. This has several
150 * effects, concluding with the setting of a status flag; see the
151 * sentry documentation for more.
153 * If the sentry status is good, the function tries to extract
154 * whatever data is appropriate for the type of the argument.
156 * If an exception is thrown during extraction, ios_base::badbit
157 * will be turned on in the stream's error state (without causing an
158 * ios_base::failure to be thrown) and the original exception will
159 * be rethrown if badbit is set in the exceptions mask.
164 * @brief Integer arithmetic extractors
165 * @param __n A variable of builtin integral type.
166 * @return @c *this if successful
168 * These functions use the stream's current locale (specifically, the
169 * @c num_get facet) to parse the input data.
172 operator>>(bool& __n)
173 { return _M_extract(__n); }
176 operator>>(short& __n);
179 operator>>(unsigned short& __n)
180 { return _M_extract(__n); }
183 operator>>(int& __n);
186 operator>>(unsigned int& __n)
187 { return _M_extract(__n); }
190 operator>>(long& __n)
191 { return _M_extract(__n); }
194 operator>>(unsigned long& __n)
195 { return _M_extract(__n); }
197#ifdef _GLIBCXX_USE_LONG_LONG
198#pragma GCC diagnostic push
199#pragma GCC diagnostic ignored "-Wlong-long"
201 operator>>(long long& __n)
202 { return _M_extract(__n); }
205 operator>>(unsigned long long& __n)
206 { return _M_extract(__n); }
207#pragma GCC diagnostic pop
213 * @brief Floating point arithmetic extractors
214 * @param __f A variable of builtin floating point type.
215 * @return @c *this if successful
217 * These functions use the stream's current locale (specifically, the
218 * @c num_get facet) to parse the input data.
221 operator>>(float& __f)
222 { return _M_extract(__f); }
225 operator>>(double& __f)
226 { return _M_extract(__f); }
229 operator>>(long double& __f)
230 { return _M_extract(__f); }
233#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
234 __attribute__((__always_inline__))
236 operator>>(_Float16& __f)
239 __istream_type& __ret = _M_extract(__flt);
240 ios_base::iostate __err = ios_base::goodbit;
241 if (__flt < -__FLT16_MAX__)
243 __f = -__FLT16_MAX__;
244 __err = ios_base::failbit;
246 else if (__flt > __FLT16_MAX__)
249 __err = ios_base::failbit;
252 __f = static_cast<_Float16>(__flt);
254 this->setstate(__err);
259#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
260 __attribute__((__always_inline__))
262 operator>>(_Float32& __f)
265 __istream_type& __ret = _M_extract(__flt);
266 __f = static_cast<_Float32> (__flt);
271#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
272 __attribute__((__always_inline__))
274 operator>>(_Float64& __f)
277 __istream_type& __ret = _M_extract(__dbl);
278 __f = static_cast<_Float64> (__dbl);
283#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
284 __attribute__((__always_inline__))
286 operator>>(_Float128& __f)
289 __istream_type& __ret = _M_extract(__ldbl);
290 __f = static_cast<_Float128> (__ldbl);
295#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
296 __attribute__((__always_inline__))
298 operator>>(__gnu_cxx::__bfloat16_t & __f)
301 __istream_type& __ret = _M_extract(__flt);
302 ios_base::iostate __err = ios_base::goodbit;
303 if (__flt < -__BFLT16_MAX__)
305 __f = -__BFLT16_MAX__;
306 __err = ios_base::failbit;
308 else if (__flt > __BFLT16_MAX__)
310 __f = __BFLT16_MAX__;
311 __err = ios_base::failbit;
314 __f = static_cast<__gnu_cxx::__bfloat16_t>(__flt);
316 this->setstate(__err);
322 * @brief Basic arithmetic extractors
323 * @param __p A variable of pointer type.
324 * @return @c *this if successful
326 * These functions use the stream's current locale (specifically, the
327 * @c num_get facet) to parse the input data.
330 operator>>(void*& __p)
331 { return _M_extract(__p); }
334 * @brief Extracting into another streambuf.
335 * @param __sb A pointer to a streambuf
337 * This function behaves like one of the basic arithmetic extractors,
338 * in that it also constructs a sentry object and has the same error
341 * If @p __sb is NULL, the stream will set failbit in its error state.
343 * Characters are extracted from this stream and inserted into the
344 * @p __sb streambuf until one of the following occurs:
346 * - the input stream reaches end-of-file,
347 * - insertion into the output buffer fails (in this case, the
348 * character that would have been inserted is not extracted), or
349 * - an exception occurs (and in this case is caught)
351 * If the function inserts no characters, failbit is set.
354 operator>>(__streambuf_type* __sb);
357 // [27.6.1.3] unformatted input
359 * @brief Character counting
360 * @return The number of characters extracted by the previous
361 * unformatted input function dispatched for this stream.
365 { return _M_gcount; }
369 * @name Unformatted Input Functions
371 * All the unformatted input functions have some common behavior.
372 * Each starts by constructing a temporary object of type
373 * std::basic_istream::sentry with the second argument (noskipws)
374 * set to true. This has several effects, concluding with the
375 * setting of a status flag; see the sentry documentation for more.
377 * If the sentry status is good, the function tries to extract
378 * whatever data is appropriate for the type of the argument.
380 * The number of characters extracted is stored for later retrieval
383 * If an exception is thrown during extraction, ios_base::badbit
384 * will be turned on in the stream's error state (without causing an
385 * ios_base::failure to be thrown) and the original exception will
386 * be rethrown if badbit is set in the exceptions mask.
390 * @brief Simple extraction.
391 * @return A character, or eof().
393 * Tries to extract a character. If none are available, sets failbit
394 * and returns traits::eof().
400 * @brief Simple extraction.
401 * @param __c The character in which to store data.
404 * Tries to extract a character and store it in @a __c. If none are
405 * available, sets failbit and returns traits::eof().
407 * @note This function is not overloaded on signed char and
414 * @brief Simple multiple-character extraction.
415 * @param __s Pointer to an array.
416 * @param __n Maximum number of characters to store in @a __s.
417 * @param __delim A "stop" character.
420 * Characters are extracted and stored into @a __s until one of the
423 * - @c __n-1 characters are stored
424 * - the input sequence reaches EOF
425 * - the next character equals @a __delim, in which case the character
428 * If no characters are stored, failbit is set in the stream's error
431 * In any case, a null character is stored into the next location in
434 * @note This function is not overloaded on signed char and
438 get(char_type* __s, streamsize __n, char_type __delim);
441 * @brief Simple multiple-character extraction.
442 * @param __s Pointer to an array.
443 * @param __n Maximum number of characters to store in @a s.
446 * Returns @c get(__s,__n,widen('\\n')).
449 get(char_type* __s, streamsize __n)
450 { return this->get(__s, __n, this->widen('\n')); }
453 * @brief Extraction into another streambuf.
454 * @param __sb A streambuf in which to store data.
455 * @param __delim A "stop" character.
458 * Characters are extracted and inserted into @a __sb until one of the
461 * - the input sequence reaches EOF
462 * - insertion into the output buffer fails (in this case, the
463 * character that would have been inserted is not extracted)
464 * - the next character equals @a __delim (in this case, the character
466 * - an exception occurs (and in this case is caught)
468 * If no characters are stored, failbit is set in the stream's error
472 get(__streambuf_type& __sb, char_type __delim);
475 * @brief Extraction into another streambuf.
476 * @param __sb A streambuf in which to store data.
479 * Returns @c get(__sb,widen('\\n')).
482 get(__streambuf_type& __sb)
483 { return this->get(__sb, this->widen('\n')); }
486 * @brief String extraction.
487 * @param __s A character array in which to store the data.
488 * @param __n Maximum number of characters to extract.
489 * @param __delim A "stop" character.
492 * Extracts and stores characters into @a __s until one of the
493 * following happens. Note that these criteria are required to be
494 * tested in the order listed here, to allow an input line to exactly
495 * fill the @a __s array without setting failbit.
497 * -# the input sequence reaches end-of-file, in which case eofbit
498 * is set in the stream error state
499 * -# the next character equals @c __delim, in which case the character
500 * is extracted (and therefore counted in @c gcount()) but not stored
501 * -# @c __n-1 characters are stored, in which case failbit is set
502 * in the stream error state
504 * If no characters are extracted, failbit is set. (An empty line of
505 * input should therefore not cause failbit to be set.)
507 * In any case, a null character is stored in the next location in
511 getline(char_type* __s, streamsize __n, char_type __delim);
514 * @brief String extraction.
515 * @param __s A character array in which to store the data.
516 * @param __n Maximum number of characters to extract.
519 * Returns @c getline(__s,__n,widen('\\n')).
522 getline(char_type* __s, streamsize __n)
523 { return this->getline(__s, __n, this->widen('\n')); }
526 * @brief Discarding characters
527 * @param __n Number of characters to discard.
528 * @param __delim A "stop" character.
531 * Extracts characters and throws them away until one of the
533 * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
534 * characters are extracted
535 * - the input sequence reaches end-of-file
536 * - the next character equals @a __delim (in this case, the character
537 * is extracted); note that this condition will never occur if
538 * @a __delim equals @c traits::eof().
540 * NB: Provide three overloads, instead of the single function
541 * (with defaults) mandated by the Standard: this leads to a
542 * better performing implementation, while still conforming to
546 ignore(streamsize __n, int_type __delim);
549 ignore(streamsize __n);
555 * @brief Looking ahead in the stream
556 * @return The next character, or eof().
558 * If, after constructing the sentry object, @c good() is false,
559 * returns @c traits::eof(). Otherwise reads but does not extract
560 * the next input character.
566 * @brief Extraction without delimiters.
567 * @param __s A character array.
568 * @param __n Maximum number of characters to store.
571 * If the stream state is @c good(), extracts characters and stores
572 * them into @a __s until one of the following happens:
573 * - @a __n characters are stored
574 * - the input sequence reaches end-of-file, in which case the error
575 * state is set to @c failbit|eofbit.
577 * @note This function is not overloaded on signed char and
581 read(char_type* __s, streamsize __n);
584 * @brief Extraction until the buffer is exhausted, but no more.
585 * @param __s A character array.
586 * @param __n Maximum number of characters to store.
587 * @return The number of characters extracted.
589 * Extracts characters and stores them into @a __s depending on the
590 * number of characters remaining in the streambuf's buffer,
591 * @c rdbuf()->in_avail(), called @c A here:
592 * - if @c A @c == @c -1, sets eofbit and extracts no characters
593 * - if @c A @c == @c 0, extracts no characters
594 * - if @c A @c > @c 0, extracts @c min(A,n)
596 * The goal is to empty the current buffer, and to not request any
597 * more from the external input sequence controlled by the streambuf.
600 readsome(char_type* __s, streamsize __n);
603 * @brief Unextracting a single character.
604 * @param __c The character to push back into the input stream.
607 * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
609 * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
612 * @note This function first clears eofbit. Since no characters
613 * are extracted, the next call to @c gcount() will return 0,
614 * as required by DR 60.
617 putback(char_type __c);
620 * @brief Unextracting the previous character.
623 * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
625 * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
628 * @note This function first clears eofbit. Since no characters
629 * are extracted, the next call to @c gcount() will return 0,
630 * as required by DR 60.
636 * @brief Synchronizing the stream buffer.
637 * @return 0 on success, -1 on failure
639 * If @c rdbuf() is a null pointer, returns -1.
641 * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
642 * sets badbit and returns -1.
644 * Otherwise, returns 0.
646 * @note This function does not count the number of characters
647 * extracted, if any, and therefore does not affect the next
648 * call to @c gcount().
654 * @brief Getting the current read position.
655 * @return A file position object.
657 * If @c fail() is not false, returns @c pos_type(-1) to indicate
658 * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
660 * @note This function does not count the number of characters
661 * extracted, if any, and therefore does not affect the next
662 * call to @c gcount(). At variance with putback, unget and
663 * seekg, eofbit is not cleared first.
669 * @brief Changing the current read position.
670 * @param __pos A file position object.
673 * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If
674 * that function fails, sets failbit.
676 * @note This function first clears eofbit. It does not count the
677 * number of characters extracted, if any, and therefore does
678 * not affect the next call to @c gcount().
684 * @brief Changing the current read position.
685 * @param __off A file offset object.
686 * @param __dir The direction in which to seek.
689 * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
690 * If that function fails, sets failbit.
692 * @note This function first clears eofbit. It does not count the
693 * number of characters extracted, if any, and therefore does
694 * not affect the next call to @c gcount().
697 seekg(off_type, ios_base::seekdir);
702 : _M_gcount(streamsize(0))
705#if __cplusplus >= 201103L
706 basic_istream(const basic_istream&) = delete;
708 basic_istream(basic_istream&& __rhs)
709 : __ios_type(), _M_gcount(__rhs._M_gcount)
711 __ios_type::move(__rhs);
715 // 27.7.3.3 Assign/swap
717 basic_istream& operator=(const basic_istream&) = delete;
720 operator=(basic_istream&& __rhs)
727 swap(basic_istream& __rhs)
729 __ios_type::swap(__rhs);
730 std::swap(_M_gcount, __rhs._M_gcount);
734 template<typename _ValueT>
736 _M_extract(_ValueT& __v);
739 /// Explicit specialization declarations, defined in src/istream.cc.
742 basic_istream<char>::
743 getline(char_type* __s, streamsize __n, char_type __delim);
747 basic_istream<char>::
748 ignore(streamsize __n);
752 basic_istream<char>::
753 ignore(streamsize __n, int_type __delim);
755#ifdef _GLIBCXX_USE_WCHAR_T
757 basic_istream<wchar_t>&
758 basic_istream<wchar_t>::
759 getline(char_type* __s, streamsize __n, char_type __delim);
762 basic_istream<wchar_t>&
763 basic_istream<wchar_t>::
764 ignore(streamsize __n);
767 basic_istream<wchar_t>&
768 basic_istream<wchar_t>::
769 ignore(streamsize __n, int_type __delim);
773 * @brief Performs setup work for input streams.
775 * Objects of this class are created before all of the standard
776 * extractors are run. It is responsible for <em>exception-safe
777 * prefix and suffix operations,</em> although only prefix actions
778 * are currently required by the standard.
780 template<typename _CharT, typename _Traits>
781 class basic_istream<_CharT, _Traits>::sentry
787 /// Easy access to dependent types.
788 typedef _Traits traits_type;
789 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
790 typedef basic_istream<_CharT, _Traits> __istream_type;
791 typedef typename __istream_type::__ctype_type __ctype_type;
792 typedef typename _Traits::int_type __int_type;
795 * @brief The constructor performs all the work.
796 * @param __is The input stream to guard.
797 * @param __noskipws Whether to consume whitespace or not.
799 * If the stream state is good (@a __is.good() is true), then the
800 * following actions are performed, otherwise the sentry state
801 * is false (<em>not okay</em>) and failbit is set in the
804 * The sentry's preparatory actions are:
806 * -# if the stream is tied to an output stream, @c is.tie()->flush()
807 * is called to synchronize the output sequence
808 * -# if @a __noskipws is false, and @c ios_base::skipws is set in
809 * @c is.flags(), the sentry extracts and discards whitespace
810 * characters from the stream. The currently imbued locale is
811 * used to determine whether each character is whitespace.
813 * If the stream state is still good, then the sentry state becomes
817 sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
820 * @brief Quick status checking.
821 * @return The sentry state.
823 * For ease of use, sentries may be converted to booleans. The
824 * return value is that of the sentry state (true == okay).
826#if __cplusplus >= 201103L
829 operator bool() const
835 * @brief Character extractors
836 * @param __in An input stream.
837 * @param __c A character reference.
840 * Behaves like one of the formatted arithmetic extractors described in
841 * std::basic_istream. After constructing a sentry object with good
842 * status, this function extracts a character (if one is available) and
843 * stores it in @a __c. Otherwise, sets failbit in the input stream.
845 template<typename _CharT, typename _Traits>
846 basic_istream<_CharT, _Traits>&
847 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
849 template<class _Traits>
850 inline basic_istream<char, _Traits>&
851 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
852 { return (__in >> reinterpret_cast<char&>(__c)); }
854 template<class _Traits>
855 inline basic_istream<char, _Traits>&
856 operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
857 { return (__in >> reinterpret_cast<char&>(__c)); }
861 template<typename _CharT, typename _Traits>
863 __istream_extract(basic_istream<_CharT, _Traits>&, _CharT*, streamsize);
865 void __istream_extract(istream&, char*, streamsize);
869 * @brief Character string extractors
870 * @param __in An input stream.
871 * @param __s A character array (or a pointer to an array before C++20).
874 * Behaves like one of the formatted arithmetic extractors described in
875 * `std::basic_istream`. After constructing a sentry object with good
876 * status, this function extracts up to `n` characters and stores them
877 * into the array `__s`. `n` is defined as:
879 * - if `width()` is greater than zero, `n` is `min(width(), n)`
880 * - otherwise `n` is the number of elements of the array
881 * - (before C++20 the pointer is assumed to point to an array of
882 * the largest possible size for an array of `char_type`).
884 * Characters are extracted and stored until one of the following happens:
885 * - `n - 1` characters are stored
887 * - the next character is whitespace according to the current locale
889 * `width(0)` is then called for the input stream.
891 * If no characters are extracted, sets failbit.
894#if __cplusplus <= 201703L
895 template<typename _CharT, typename _Traits>
896 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
897 inline basic_istream<_CharT, _Traits>&
898 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
901 // Function inlining might make the buffer size known, allowing us to
903 size_t __n = __builtin_object_size(__s, 0);
904 if (__n < sizeof(_CharT))
906 // There is not even space for the required null terminator.
907 __glibcxx_assert(__n >= sizeof(_CharT));
908 // No point calling __istream_extract, but still need to reset width.
910 __in.setstate(ios_base::failbit);
912 else if (__n != (size_t)-1)
914 __n /= sizeof(_CharT);
915 streamsize __w = __in.width();
916 std::__istream_extract(__in, __s, __n);
917 if (__in.good() && (__w <= 0 || __n < (size_t)__w))
919 // Stopped extracting early to avoid overflowing the buffer,
920 // but might have stopped anyway (and set eofbit) if at EOF.
921 const typename _Traits::int_type __c = __in.rdbuf()->sgetc();
922 const bool __eof = _Traits::eq_int_type(__c, _Traits::eof());
923 if (__builtin_expect(__eof, true)) // Assume EOF, not overflow.
924 __in.setstate(ios_base::eofbit);
930 // Buffer size is unknown, have to assume it's huge.
931 streamsize __n = __gnu_cxx::__numeric_traits<streamsize>::__max;
932 __n /= sizeof(_CharT);
933 std::__istream_extract(__in, __s, __n);
938 template<class _Traits>
939 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
940 inline basic_istream<char, _Traits>&
941 operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
942 { return __in >> reinterpret_cast<char*>(__s); }
944 template<class _Traits>
945 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
946 inline basic_istream<char, _Traits>&
947 operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
948 { return __in >> reinterpret_cast<char*>(__s); }
950 // _GLIBCXX_RESOLVE_LIB_DEFECTS
951 // 2499. operator>>(istream&, char*) makes it hard to avoid buffer overflows
952 template<typename _CharT, typename _Traits, size_t _Num>
953 inline basic_istream<_CharT, _Traits>&
954 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT (&__s)[_Num])
956 static_assert(_Num <= __gnu_cxx::__numeric_traits<streamsize>::__max);
957 std::__istream_extract(__in, __s, _Num);
961 template<class _Traits, size_t _Num>
962 inline basic_istream<char, _Traits>&
963 operator>>(basic_istream<char, _Traits>& __in, unsigned char (&__s)[_Num])
964 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
966 template<class _Traits, size_t _Num>
967 inline basic_istream<char, _Traits>&
968 operator>>(basic_istream<char, _Traits>& __in, signed char (&__s)[_Num])
969 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
974 * @brief Template class basic_iostream
977 * @tparam _CharT Type of character stream.
978 * @tparam _Traits Traits for character type, defaults to
979 * char_traits<_CharT>.
981 * This class multiply inherits from the input and output stream classes
982 * simply to provide a single interface.
984 template<typename _CharT, typename _Traits>
986 : public basic_istream<_CharT, _Traits>,
987 public basic_ostream<_CharT, _Traits>
990 // _GLIBCXX_RESOLVE_LIB_DEFECTS
991 // 271. basic_iostream missing typedefs
992 // Types (inherited):
993 typedef _CharT char_type;
994 typedef typename _Traits::int_type int_type;
995 typedef typename _Traits::pos_type pos_type;
996 typedef typename _Traits::off_type off_type;
997 typedef _Traits traits_type;
999 // Non-standard Types:
1000 typedef basic_istream<_CharT, _Traits> __istream_type;
1001 typedef basic_ostream<_CharT, _Traits> __ostream_type;
1004 * @brief Constructor does nothing.
1006 * Both of the parent classes are initialized with the same
1007 * streambuf pointer passed to this constructor.
1010 basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
1011 : __istream_type(__sb), __ostream_type(__sb) { }
1014 * @brief Destructor does nothing.
1017 ~basic_iostream() { }
1021 : __istream_type(), __ostream_type() { }
1023#if __cplusplus >= 201103L
1024 basic_iostream(const basic_iostream&) = delete;
1026 basic_iostream(basic_iostream&& __rhs)
1027 : __istream_type(std::move(__rhs)), __ostream_type(*this)
1030 // 27.7.3.3 Assign/swap
1032 basic_iostream& operator=(const basic_iostream&) = delete;
1035 operator=(basic_iostream&& __rhs)
1042 swap(basic_iostream& __rhs)
1043 { __istream_type::swap(__rhs); }
1048 * @brief Quick and easy way to eat whitespace
1050 * This manipulator extracts whitespace characters, stopping when the
1051 * next character is non-whitespace, or when the input sequence is empty.
1052 * If the sequence is empty, @c eofbit is set in the stream, but not
1055 * The current locale is used to distinguish whitespace characters.
1061 * std::cin >> std::ws >> mc;
1063 * will skip leading whitespace before calling operator>> on cin and your
1064 * object. Note that the same effect can be achieved by creating a
1065 * std::basic_istream::sentry inside your definition of operator>>.
1067 template<typename _CharT, typename _Traits>
1068 basic_istream<_CharT, _Traits>&
1069 ws(basic_istream<_CharT, _Traits>& __is);
1071#if __cplusplus >= 201103L
1072 // C++11 27.7.2.6 Rvalue stream extraction [istream.rvalue]
1073 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1074 // 2328. Rvalue stream extraction should use perfect forwarding
1075 // 1203. More useful rvalue stream insertion
1077#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
1078 template<typename _Is, typename _Tp>
1079 requires __derived_from_ios_base<_Is>
1080 && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); }
1081 using __rvalue_stream_extraction_t = _Is&&;
1083 template<typename _Is, typename _Tp,
1084 typename = _Require_derived_from_ios_base<_Is>,
1085 typename = decltype(std::declval<_Is&>() >> std::declval<_Tp>())>
1086 using __rvalue_stream_extraction_t = _Is&&;
1090 * @brief Generic extractor for rvalue stream
1091 * @param __is An input stream.
1092 * @param __x A reference to the extraction target.
1095 * This is just a forwarding function to allow extraction from
1096 * rvalue streams since they won't bind to the extractor functions
1097 * that take an lvalue reference.
1099 template<typename _Istream, typename _Tp>
1100 inline __rvalue_stream_extraction_t<_Istream, _Tp>
1101 operator>>(_Istream&& __is, _Tp&& __x)
1103 __is >> std::forward<_Tp>(__x);
1104 return std::move(__is);
1108_GLIBCXX_END_NAMESPACE_VERSION
1111#include <bits/istream.tcc>
1113#endif /* _GLIBCXX_ISTREAM */