std_istream.h revision 132720
180709Sjake// Input streams -*- C++ -*-
280709Sjake
380709Sjake// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
480709Sjake// Free Software Foundation, Inc.
580709Sjake//
680709Sjake// This file is part of the GNU ISO C++ Library.  This library is free
780709Sjake// software; you can redistribute it and/or modify it under the
880709Sjake// terms of the GNU General Public License as published by the
980709Sjake// Free Software Foundation; either version 2, or (at your option)
1080709Sjake// any later version.
1180709Sjake
1280709Sjake// This library is distributed in the hope that it will be useful,
1380709Sjake// but WITHOUT ANY WARRANTY; without even the implied warranty of
1481337Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1580709Sjake// GNU General Public License for more details.
1680709Sjake
1781337Sobrien// You should have received a copy of the GNU General Public License along
1880709Sjake// with this library; see the file COPYING.  If not, write to the Free
1980709Sjake// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
2080709Sjake// USA.
2180709Sjake
2280709Sjake// As a special exception, you may use this file as part of a free software
2380709Sjake// library without restriction.  Specifically, if other files instantiate
2480709Sjake// templates or use macros or inline functions from this file, or you compile
2580709Sjake// this file and link it with other files to produce an executable, this
2680709Sjake// file does not by itself cause the resulting executable to be covered by
2780709Sjake// the GNU General Public License.  This exception does not however
2880709Sjake// invalidate any other reasons why the executable file might be covered by
2980709Sjake// the GNU General Public License.
3080709Sjake
3180709Sjake//
3280709Sjake// ISO C++ 14882: 27.6.1  Input streams
3382910Sjake//
3480709Sjake
3580709Sjake/** @file istream
3680709Sjake *  This is a Standard C++ Library header.  You should @c #include this header
3784186Sjake *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
3880709Sjake */
3980709Sjake
4081381Sjake#ifndef _GLIBCXX_ISTREAM
4181381Sjake#define _GLIBCXX_ISTREAM 1
4281381Sjake
4381381Sjake#pragma GCC system_header
4480709Sjake
4580709Sjake#include <ios>
4680709Sjake#include <limits> // For numeric_limits
4780709Sjake
4881135Stmmnamespace std
4980709Sjake{
5080709Sjake  // [27.6.1.1] Template class basic_istream
5181614Sjake  /**
5280709Sjake   *  @brief  Controlling input.
5380709Sjake   *
5480709Sjake   *  This is the base class for all input streams.  It provides text
5582910Sjake   *  formatting of all builtin types, and communicates with any class
5680709Sjake   *  derived from basic_streambuf to do the actual input.
5780709Sjake  */
5880709Sjake  template<typename _CharT, typename _Traits>
5980709Sjake    class basic_istream : virtual public basic_ios<_CharT, _Traits>
6082010Sjake    {
6180709Sjake    public:
6283756Sjake      // Types (inherited from basic_ios (27.4.4)):
6383756Sjake      typedef _CharT                     		char_type;
6480709Sjake      typedef typename _Traits::int_type 		int_type;
6580709Sjake      typedef typename _Traits::pos_type 		pos_type;
6680709Sjake      typedef typename _Traits::off_type 		off_type;
6783366Sjulian      typedef _Traits                    		traits_type;
6884186Sjake
6983366Sjulian      // Non-standard Types:
7080709Sjake      typedef basic_streambuf<_CharT, _Traits> 		__streambuf_type;
7180709Sjake      typedef basic_ios<_CharT, _Traits>		__ios_type;
7282910Sjake      typedef basic_istream<_CharT, _Traits>		__istream_type;
7380709Sjake      typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
7481135Stmm 							__num_get_type;
7581135Stmm      typedef ctype<_CharT>           			__ctype_type;
7681135Stmm
7781135Stmm      template<typename _CharT2, typename _Traits2>
7881381Sjake        friend basic_istream<_CharT2, _Traits2>&
7981381Sjake        operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2&);
8081381Sjake
8181381Sjake      template<typename _CharT2, typename _Traits2>
8280709Sjake        friend basic_istream<_CharT2, _Traits2>&
8381381Sjake        operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*);
8481381Sjake
8581381Sjake    protected:
8680709Sjake      // Data Members:
8785244Sjake      /**
8880709Sjake       *  @if maint
8980709Sjake       *  The number of characters extracted in the previous unformatted
9080709Sjake       *  function; see gcount().
9180709Sjake       *  @endif
9282910Sjake      */
9385244Sjake      streamsize 		_M_gcount;
9484186Sjake
9584186Sjake    public:
9684186Sjake      // [27.6.1.1.1] constructor/destructor
9782910Sjake      /**
9885244Sjake       *  @brief  Base constructor.
9985244Sjake       *
10085244Sjake       *  This ctor is almost never called by the user directly, rather from
10182910Sjake       *  derived classes' initialization lists, which pass a pointer to
10282910Sjake       *  their own stream buffer.
10382910Sjake      */
10482910Sjake      explicit
10582910Sjake      basic_istream(__streambuf_type* __sb): _M_gcount(streamsize(0))
10682910Sjake      { this->init(__sb); }
10782910Sjake
10882910Sjake      /**
10982910Sjake       *  @brief  Base destructor.
11080709Sjake       *
11180709Sjake       *  This does very little apart from providing a virtual base dtor.
11281381Sjake      */
11380709Sjake      virtual
11481381Sjake      ~basic_istream()
11580709Sjake      { _M_gcount = streamsize(0); }
11680709Sjake
11780709Sjake      // [27.6.1.1.2] prefix/suffix
11880709Sjake      class sentry;
11981614Sjake      friend class sentry;
12081381Sjake
12180709Sjake      // [27.6.1.2] formatted input
12280709Sjake      // [27.6.1.2.3] basic_istream::operator>>
12380709Sjake      //@{
12480709Sjake      /**
12580709Sjake       *  @brief  Interface for manipulators.
12680709Sjake       *
12780709Sjake       *  Manuipulators such as @c std::ws and @c std::dec use these
12884186Sjake       *  functions in constructs like "std::cin >> std::ws".  For more
12984186Sjake       *  information, see the iomanip header.
13083366Sjulian      */
13180709Sjake      inline __istream_type&
13282910Sjake      operator>>(__istream_type& (*__pf)(__istream_type&));
13380709Sjake
13484186Sjake      inline __istream_type&
13584186Sjake      operator>>(__ios_type& (*__pf)(__ios_type&));
13684186Sjake
13781614Sjake      inline __istream_type&
13881614Sjake      operator>>(ios_base& (*__pf)(ios_base&));
13981614Sjake      //@}
14081614Sjake
14181614Sjake      // [27.6.1.2.2] arithmetic extractors
14281614Sjake      /**
14381614Sjake       *  @name Arithmetic Extractors
14481614Sjake       *
14581614Sjake       *  All the @c operator>> functions (aka <em>formatted input
14681614Sjake       *  functions</em>) have some common behavior.  Each starts by
14781614Sjake       *  constructing a temporary object of type std::basic_istream::sentry
14881614Sjake       *  with the second argument (noskipws) set to false.  This has several
14981614Sjake       *  effects, concluding with the setting of a status flag; see the
15081614Sjake       *  sentry documentation for more.
15181614Sjake       *
15281614Sjake       *  If the sentry status is good, the function tries to extract
15385244Sjake       *  whatever data is appropriate for the type of the argument.
15485244Sjake       *
15580709Sjake       *  If an exception is thrown during extraction, ios_base::badbit
15680709Sjake       *  will be turned on in the stream's error state without causing an
15780709Sjake       *  ios_base::failure to be thrown.  The original exception will then
15880709Sjake       *  be rethrown.
15983366Sjulian      */
16083366Sjulian      //@{
16182910Sjake      /**
16282910Sjake       *  @brief  Basic arithmetic extractors
16382910Sjake       *  @param  A variable of builtin type.
16480709Sjake       *  @return  @c *this if successful
16580709Sjake       *
16683366Sjulian       *  These functions use the stream's current locale (specifically, the
16783366Sjulian       *  @c num_get facet) to parse the input data.
16883366Sjulian      */
16983366Sjulian      __istream_type&
17083366Sjulian      operator>>(bool& __n);
17183366Sjulian
17283366Sjulian      __istream_type&
17383366Sjulian      operator>>(short& __n);
17484186Sjake
17581135Stmm      __istream_type&
17680709Sjake      operator>>(unsigned short& __n);
17780709Sjake
17882010Sjake      __istream_type&
17980709Sjake      operator>>(int& __n);
18082010Sjake
18182910Sjake      __istream_type&
18282910Sjake      operator>>(unsigned int& __n);
18382910Sjake
18480709Sjake      __istream_type&
18581381Sjake      operator>>(long& __n);
18681381Sjake
18781381Sjake      __istream_type&
18881381Sjake      operator>>(unsigned long& __n);
18981135Stmm
19081135Stmm#ifdef _GLIBCXX_USE_LONG_LONG
19181135Stmm      __istream_type&
19281135Stmm      operator>>(long long& __n);
19381135Stmm
19481135Stmm      __istream_type&
19581135Stmm      operator>>(unsigned long long& __n);
19680709Sjake#endif
19780709Sjake
19880709Sjake      __istream_type&
19982910Sjake      operator>>(float& __f);
20082010Sjake
20180709Sjake      __istream_type&
20280709Sjake      operator>>(double& __f);
20380709Sjake
20480709Sjake      __istream_type&
20580709Sjake      operator>>(long double& __f);
20680709Sjake
20780709Sjake      __istream_type&
20880709Sjake      operator>>(void*& __p);
20980709Sjake
21080709Sjake      /**
21180709Sjake       *  @brief  Extracting into another streambuf.
21280709Sjake       *  @param  sb  A pointer to a streambuf
21380709Sjake       *
21480709Sjake       *  This function behaves like one of the basic arithmetic extractors,
21580709Sjake       *  in that it also constructs a sentry object and has the same error
21680709Sjake       *  handling behavior.
21780709Sjake       *
21880709Sjake       *  If @a sb is NULL, the stream will set failbit in its error state.
21980709Sjake       *
22080709Sjake       *  Characters are extracted from this stream and inserted into the
22180709Sjake       *  @a sb streambuf until one of the following occurs:
22280709Sjake       *
22380709Sjake       *  - the input stream reaches end-of-file,
22480709Sjake       *  - insertion into the output buffer fails (in this case, the
22582910Sjake       *    character that would have been inserted is not extracted), or
22681614Sjake       *  - an exception occurs (and in this case is caught)
22780709Sjake       *
22880709Sjake       *  If the function inserts no characters, failbit is set.
22980709Sjake      */
23080709Sjake      __istream_type&
23182910Sjake      operator>>(__streambuf_type* __sb);
23280709Sjake      //@}
23380709Sjake
234      // [27.6.1.3] unformatted input
235      /**
236       *  @brief  Character counting
237       *  @return  The number of characters extracted by the previous
238       *           unformatted input function dispatched for this stream.
239      */
240      inline streamsize
241      gcount() const
242      { return _M_gcount; }
243
244      /**
245       *  @name Unformatted Input Functions
246       *
247       *  All the unformatted input functions have some common behavior.
248       *  Each starts by constructing a temporary object of type
249       *  std::basic_istream::sentry with the second argument (noskipws)
250       *  set to true.  This has several effects, concluding with the
251       *  setting of a status flag; see the sentry documentation for more.
252       *
253       *  If the sentry status is good, the function tries to extract
254       *  whatever data is appropriate for the type of the argument.
255       *
256       *  The number of characters extracted is stored for later retrieval
257       *  by gcount().
258       *
259       *  If an exception is thrown during extraction, ios_base::badbit
260       *  will be turned on in the stream's error state without causing an
261       *  ios_base::failure to be thrown.  The original exception will then
262       *  be rethrown.
263      */
264      //@{
265      /**
266       *  @brief  Simple extraction.
267       *  @return  A character, or eof().
268       *
269       *  Tries to extract a character.  If none are available, sets failbit
270       *  and returns traits::eof().
271      */
272      int_type
273      get();
274
275      /**
276       *  @brief  Simple extraction.
277       *  @param  c  The character in which to store data.
278       *  @return  *this
279       *
280       *  Tries to extract a character and store it in @a c.  If none are
281       *  available, sets failbit and returns traits::eof().
282       *
283       *  @note  This function is not overloaded on signed char and
284       *         unsigned char.
285      */
286      __istream_type&
287      get(char_type& __c);
288
289      /**
290       *  @brief  Simple multiple-character extraction.
291       *  @param  s  Pointer to an array.
292       *  @param  n  Maximum number of characters to store in @a s.
293       *  @param  delim  A "stop" character.
294       *  @return  *this
295       *
296       *  Characters are extracted and stored into @a s until one of the
297       *  following happens:
298       *
299       *  - @c n-1 characters are stored
300       *  - the input sequence reaches EOF
301       *  - the next character equals @a delim, in which case the character
302       *    is not extracted
303       *
304       * If no characters are stored, failbit is set in the stream's error
305       * state.
306       *
307       * In any case, a null character is stored into the next location in
308       * the array.
309       *
310       *  @note  This function is not overloaded on signed char and
311       *         unsigned char.
312      */
313      __istream_type&
314      get(char_type* __s, streamsize __n, char_type __delim);
315
316      /**
317       *  @brief  Simple multiple-character extraction.
318       *  @param  s  Pointer to an array.
319       *  @param  n  Maximum number of characters to store in @a s.
320       *  @return  *this
321       *
322       *  Returns @c get(s,n,widen('\n')).
323      */
324      inline __istream_type&
325      get(char_type* __s, streamsize __n)
326      { return this->get(__s, __n, this->widen('\n')); }
327
328      /**
329       *  @brief  Extraction into another streambuf.
330       *  @param  sb  A streambuf in which to store data.
331       *  @param  delim  A "stop" character.
332       *  @return  *this
333       *
334       *  Characters are extracted and inserted into @a sb until one of the
335       *  following happens:
336       *
337       *  - the input sequence reaches EOF
338       *  - insertion into the output buffer fails (in this case, the
339       *    character that would have been inserted is not extracted)
340       *  - the next character equals @a delim (in this case, the character
341       *    is not extracted)
342       *  - an exception occurs (and in this case is caught)
343       *
344       * If no characters are stored, failbit is set in the stream's error
345       * state.
346      */
347      __istream_type&
348      get(__streambuf_type& __sb, char_type __delim);
349
350      /**
351       *  @brief  Extraction into another streambuf.
352       *  @param  sb  A streambuf in which to store data.
353       *  @return  *this
354       *
355       *  Returns @c get(sb,widen('\n')).
356      */
357      inline __istream_type&
358      get(__streambuf_type& __sb)
359      { return this->get(__sb, this->widen('\n')); }
360
361      /**
362       *  @brief  String extraction.
363       *  @param  s  A character array in which to store the data.
364       *  @param  n  Maximum number of characters to extract.
365       *  @param  delim  A "stop" character.
366       *  @return  *this
367       *
368       *  Extracts and stores characters into @a s until one of the
369       *  following happens.  Note that these criteria are required to be
370       *  tested in the order listed here, to allow an input line to exactly
371       *  fill the @a s array without setting failbit.
372       *
373       *  -# the input sequence reaches end-of-file, in which case eofbit
374       *     is set in the stream error state
375       *  -# the next character equals @c delim, in which case the character
376       *     is extracted (and therefore counted in @c gcount()) but not stored
377       *  -# @c n-1 characters are stored, in which case failbit is set
378       *     in the stream error state
379       *
380       *  If no characters are extracted, failbit is set.  (An empty line of
381       *  input should therefore not cause failbit to be set.)
382       *
383       *  In any case, a null character is stored in the next location in
384       *  the array.
385      */
386      __istream_type&
387      getline(char_type* __s, streamsize __n, char_type __delim);
388
389      /**
390       *  @brief  String extraction.
391       *  @param  s  A character array in which to store the data.
392       *  @param  n  Maximum number of characters to extract.
393       *  @return  *this
394       *
395       *  Returns @c getline(s,n,widen('\n')).
396      */
397      inline __istream_type&
398      getline(char_type* __s, streamsize __n)
399      { return this->getline(__s, __n, this->widen('\n')); }
400
401      /**
402       *  @brief  Discarding characters
403       *  @param  n  Number of characters to discard.
404       *  @param  delim  A "stop" character.
405       *  @return  *this
406       *
407       *  Extracts characters and throws them away until one of the
408       *  following happens:
409       *  - if @a n @c != @c std::numeric_limits<int>::max(), @a n
410       *    characters are extracted
411       *  - the input sequence reaches end-of-file
412       *  - the next character equals @a delim (in this case, the character
413       *    is extracted); note that this condition will never occur if
414       *    @a delim equals @c traits::eof().
415      */
416      __istream_type&
417      ignore(streamsize __n = 1, int_type __delim = traits_type::eof());
418
419      /**
420       *  @brief  Looking ahead in the stream
421       *  @return  The next character, or eof().
422       *
423       *  If, after constructing the sentry object, @c good() is false,
424       *  returns @c traits::eof().  Otherwise reads but does not extract
425       *  the next input character.
426      */
427      int_type
428      peek();
429
430      /**
431       *  @brief  Extraction without delimiters.
432       *  @param  s  A character array.
433       *  @param  n  Maximum number of characters to store.
434       *  @return  *this
435       *
436       *  If the stream state is @c good(), extracts characters and stores
437       *  them into @a s until one of the following happens:
438       *  - @a n characters are stored
439       *  - the input sequence reaches end-of-file, in which case the error
440       *    state is set to @c failbit|eofbit.
441       *
442       *  @note  This function is not overloaded on signed char and
443       *         unsigned char.
444      */
445      __istream_type&
446      read(char_type* __s, streamsize __n);
447
448      /**
449       *  @brief  Extraction until the buffer is exhausted, but no more.
450       *  @param  s  A character array.
451       *  @param  n  Maximum number of characters to store.
452       *  @return  The number of characters extracted.
453       *
454       *  Extracts characters and stores them into @a s depending on the
455       *  number of characters remaining in the streambuf's buffer,
456       *  @c rdbuf()->in_avail(), called @c A here:
457       *  - if @c A @c == @c -1, sets eofbit and extracts no characters
458       *  - if @c A @c == @c 0, extracts no characters
459       *  - if @c A @c > @c 0, extracts @c min(A,n)
460       *
461       *  The goal is to empty the current buffer, and to not request any
462       *  more from the external input sequence controlled by the streambuf.
463      */
464      streamsize
465      readsome(char_type* __s, streamsize __n);
466
467      /**
468       *  @brief  Unextracting a single character.
469       *  @param  c  The character to push back into the input stream.
470       *  @return  *this
471       *
472       *  If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
473       *
474       *  If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
475       *  the error state.
476       *
477       *  @note  Since no characters are extracted, the next call to
478       *         @c gcount() will return 0, as required by DR 60.
479      */
480      __istream_type&
481      putback(char_type __c);
482
483      /**
484       *  @brief  Unextracting the previous character.
485       *  @return  *this
486       *
487       *  If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
488       *
489       *  If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
490       *  the error state.
491       *
492       *  @note  Since no characters are extracted, the next call to
493       *         @c gcount() will return 0, as required by DR 60.
494      */
495      __istream_type&
496      unget();
497
498      /**
499       *  @brief  Synchronizing the stream buffer.
500       *  @return  0 on success, -1 on failure
501       *
502       *  If @c rdbuf() is a null pointer, returns -1.
503       *
504       *  Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
505       *  sets badbit and returns -1.
506       *
507       *  Otherwise, returns 0.
508       *
509       *  @note  This function does not count the number of characters
510       *         extracted, if any, and therefore does not affect the next
511       *         call to @c gcount().
512      */
513      int
514      sync();
515
516      /**
517       *  @brief  Getting the current read position.
518       *  @return  A file position object.
519       *
520       *  If @c fail() is not false, returns @c pos_type(-1) to indicate
521       *  failure.  Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
522       *
523       *  @note  This function does not count the number of characters
524       *         extracted, if any, and therefore does not affect the next
525       *         call to @c gcount().
526      */
527      pos_type
528      tellg();
529
530      /**
531       *  @brief  Changing the current read position.
532       *  @param  pos  A file position object.
533       *  @return  *this
534       *
535       *  If @c fail() is not true, calls @c rdbuf()->pubseekpos(pos).  If
536       *  that function fails, sets failbit.
537       *
538       *  @note  This function does not count the number of characters
539       *         extracted, if any, and therefore does not affect the next
540       *         call to @c gcount().
541      */
542      __istream_type&
543      seekg(pos_type);
544
545      /**
546       *  @brief  Changing the current read position.
547       *  @param  off  A file offset object.
548       *  @param  dir  The direction in which to seek.
549       *  @return  *this
550       *
551       *  If @c fail() is not true, calls @c rdbuf()->pubseekoff(off,dir).
552       *  If that function fails, sets failbit.
553       *
554       *  @note  This function does not count the number of characters
555       *         extracted, if any, and therefore does not affect the next
556       *         call to @c gcount().
557      */
558      __istream_type&
559      seekg(off_type, ios_base::seekdir);
560      //@}
561
562    protected:
563      explicit
564      basic_istream(): _M_gcount(streamsize(0)) { }
565    };
566
567  /**
568   *  @brief  Performs setup work for input streams.
569   *
570   *  Objects of this class are created before all of the standard
571   *  extractors are run.  It is responsible for "exception-safe prefix and
572   *  suffix operations," although only prefix actions are currently required
573   *  by the standard.  Additional actions may be added by the
574   *  implementation, and we list them in
575   *  http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/howto.html#5
576   *  under [27.6] notes.
577  */
578  template<typename _CharT, typename _Traits>
579    class basic_istream<_CharT, _Traits>::sentry
580    {
581    public:
582      /// Easy access to dependant types.
583      typedef _Traits 					traits_type;
584      typedef basic_streambuf<_CharT, _Traits> 		__streambuf_type;
585      typedef basic_istream<_CharT, _Traits> 		__istream_type;
586      typedef typename __istream_type::__ctype_type 	__ctype_type;
587      typedef typename _Traits::int_type		__int_type;
588
589      /**
590       *  @brief  The constructor performs all the work.
591       *  @param  is  The input stream to guard.
592       *  @param  noskipws  Whether to consume whitespace or not.
593       *
594       *  If the stream state is good (@a is.good() is true), then the
595       *  following actions are performed, otherwise the sentry state is
596       *  false ("not okay") and failbit is set in the stream state.
597       *
598       *  The sentry's preparatory actions are:
599       *
600       *  -# if the stream is tied to an output stream, @c is.tie()->flush()
601       *     is called to synchronize the output sequence
602       *  -# if @a noskipws is false, and @c ios_base::skipws is set in
603       *     @c is.flags(), the sentry extracts and discards whitespace
604       *     characters from the stream.  The currently imbued locale is
605       *     used to determine whether each character is whitespace.
606       *
607       *  If the stream state is still good, then the sentry state becomes
608       *  true ("okay").
609      */
610      explicit
611      sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
612
613      /**
614       *  @brief  Quick status checking.
615       *  @return  The sentry state.
616       *
617       *  For ease of use, sentries may be converted to booleans.  The
618       *  return value is that of the sentry state (true == okay).
619      */
620      operator bool() const { return _M_ok; }
621
622    private:
623      bool _M_ok;
624    };
625
626  // [27.6.1.2.3] character extraction templates
627  //@{
628  /**
629   *  @brief  Character extractors
630   *  @param  in  An input stream.
631   *  @param  c  A character reference.
632   *  @return  in
633   *
634   *  Behaves like one of the formatted arithmetic extractors described in
635   *  std::basic_istream.  After constructing a sentry object with good
636   *  status, this function extracts a character (if one is available) and
637   *  stores it in @a c.  Otherwise, sets failbit in the input stream.
638  */
639  template<typename _CharT, typename _Traits>
640    basic_istream<_CharT, _Traits>&
641    operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
642
643  template<class _Traits>
644    basic_istream<char, _Traits>&
645    operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
646    { return (__in >> reinterpret_cast<char&>(__c)); }
647
648  template<class _Traits>
649    basic_istream<char, _Traits>&
650    operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
651    { return (__in >> reinterpret_cast<char&>(__c)); }
652  //@}
653
654  //@{
655  /**
656   *  @brief  Character string extractors
657   *  @param  in  An input stream.
658   *  @param  s  A pointer to a character array.
659   *  @return  in
660   *
661   *  Behaves like one of the formatted arithmetic extractors described in
662   *  std::basic_istream.  After constructing a sentry object with good
663   *  status, this function extracts up to @c n characters and stores them
664   *  into the array starting at @a s.  @c n is defined as:
665   *
666   *  - if @c width() is greater than zero, @c n is width()
667   *  - otherwise @c n is "the number of elements of the largest array of
668   *    @c char_type that can store a terminating @c eos." [27.6.1.2.3]/6
669   *
670   *  Characters are extracted and stored until one of the following happens:
671   *  - @c n-1 characters are stored
672   *  - EOF is reached
673   *  - the next character is whitespace according to the current locale
674   *  - the next character is a null byte (i.e., @c charT() )
675   *
676   *  @c width(0) is then called for the input stream.
677   *
678   *  If no characters are extracted, sets failbit.
679  */
680  template<typename _CharT, typename _Traits>
681    basic_istream<_CharT, _Traits>&
682    operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
683
684  template<class _Traits>
685    basic_istream<char,_Traits>&
686    operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s)
687    { return (__in >> reinterpret_cast<char*>(__s)); }
688
689  template<class _Traits>
690    basic_istream<char,_Traits>&
691    operator>>(basic_istream<char,_Traits>& __in, signed char* __s)
692    { return (__in >> reinterpret_cast<char*>(__s)); }
693  //@}
694
695  // 27.6.1.5 Template class basic_iostream
696  /**
697   *  @brief  Merging istream and ostream capabilities.
698   *
699   *  This class multiply inherits from the input and output stream classes
700   *  simply to provide a single interface.
701  */
702  template<typename _CharT, typename _Traits>
703    class basic_iostream
704    : public basic_istream<_CharT, _Traits>,
705      public basic_ostream<_CharT, _Traits>
706    {
707    public:
708      // _GLIBCXX_RESOLVE_LIB_DEFECTS
709      // 271. basic_iostream missing typedefs
710      // Types (inherited):
711      typedef _CharT                     		char_type;
712      typedef typename _Traits::int_type 		int_type;
713      typedef typename _Traits::pos_type 		pos_type;
714      typedef typename _Traits::off_type 		off_type;
715      typedef _Traits                    		traits_type;
716
717      // Non-standard Types:
718      typedef basic_istream<_CharT, _Traits>		__istream_type;
719      typedef basic_ostream<_CharT, _Traits>		__ostream_type;
720
721      /**
722       *  @brief  Constructor does nothing.
723       *
724       *  Both of the parent classes are initialized with the same
725       *  streambuf pointer passed to this constructor.
726      */
727      explicit
728      basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
729      : __istream_type(), __ostream_type()
730      { this->init(__sb); }
731
732      /**
733       *  @brief  Destructor does nothing.
734      */
735      virtual
736      ~basic_iostream() { }
737
738    protected:
739      explicit
740      basic_iostream() : __istream_type(), __ostream_type()
741      { }
742    };
743
744  // [27.6.1.4] standard basic_istream manipulators
745  /**
746   *  @brief  Quick and easy way to eat whitespace
747   *
748   *  This manipulator extracts whitespace characters, stopping when the
749   *  next character is non-whitespace, or when the input sequence is empty.
750   *  If the sequence is empty, @c eofbit is set in the stream, but not
751   *  @c failbit.
752   *
753   *  The current locale is used to distinguish whitespace characters.
754   *
755   *  Example:
756   *  @code
757   *     MyClass   mc;
758   *
759   *     std::cin >> std::ws >> mc;
760   *  @endcode
761   *  will skip leading whitespace before calling operator>> on cin and your
762   *  object.  Note that the same effect can be achieved by creating a
763   *  std::basic_istream::sentry inside your definition of operator>>.
764  */
765  template<typename _CharT, typename _Traits>
766    basic_istream<_CharT, _Traits>&
767    ws(basic_istream<_CharT, _Traits>& __is);
768} // namespace std
769
770#ifndef _GLIBCXX_EXPORT_TEMPLATE
771# include <bits/istream.tcc>
772#endif
773
774#endif	/* _GLIBCXX_ISTREAM */
775