Home | History | Annotate | Download | only in include
      1 // Input streams -*- C++ -*-
      2 
      3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
      4 // 2006, 2007, 2008, 2009
      5 // Free Software Foundation, Inc.
      6 //
      7 // This file is part of the GNU ISO C++ Library.  This library is free
      8 // software; you can redistribute it and/or modify it under the
      9 // terms of the GNU General Public License as published by the
     10 // Free Software Foundation; either version 3, or (at your option)
     11 // any later version.
     12 
     13 // This library is distributed in the hope that it will be useful,
     14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 // GNU General Public License for more details.
     17 
     18 // Under Section 7 of GPL version 3, you are granted additional
     19 // permissions described in the GCC Runtime Library Exception, version
     20 // 3.1, as published by the Free Software Foundation.
     21 
     22 // You should have received a copy of the GNU General Public License and
     23 // a copy of the GCC Runtime Library Exception along with this program;
     24 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     25 // <http://www.gnu.org/licenses/>.
     26 
     27 //
     28 // ISO C++ 14882: 27.6.1  Input streams
     29 //
     30 
     31 /** @file istream
     32  *  This is a Standard C++ Library header.
     33  */
     34 
     35 #ifndef _GLIBCXX_ISTREAM
     36 #define _GLIBCXX_ISTREAM 1
     37 
     38 #pragma GCC system_header
     39 
     40 #include <ios>
     41 #include <ostream>
     42 
     43 _GLIBCXX_BEGIN_NAMESPACE(std)
     44 
     45   // [27.6.1.1] Template class basic_istream
     46   /**
     47    *  @brief  Controlling input.
     48    *  @ingroup io
     49    *
     50    *  This is the base class for all input streams.  It provides text
     51    *  formatting of all builtin types, and communicates with any class
     52    *  derived from basic_streambuf to do the actual input.
     53   */
     54   template<typename _CharT, typename _Traits>
     55     class basic_istream : virtual public basic_ios<_CharT, _Traits>
     56     {
     57     public:
     58       // Types (inherited from basic_ios (27.4.4)):
     59       typedef _CharT                     		char_type;
     60       typedef typename _Traits::int_type 		int_type;
     61       typedef typename _Traits::pos_type 		pos_type;
     62       typedef typename _Traits::off_type 		off_type;
     63       typedef _Traits                    		traits_type;
     64       
     65       // Non-standard Types:
     66       typedef basic_streambuf<_CharT, _Traits> 		__streambuf_type;
     67       typedef basic_ios<_CharT, _Traits>		__ios_type;
     68       typedef basic_istream<_CharT, _Traits>		__istream_type;
     69       typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >        
     70  							__num_get_type;
     71       typedef ctype<_CharT>           			__ctype_type;
     72 
     73     protected:
     74       // Data Members:
     75       /**
     76        *  The number of characters extracted in the previous unformatted
     77        *  function; see gcount().
     78       */
     79       streamsize 		_M_gcount;
     80 
     81     public:
     82       // [27.6.1.1.1] constructor/destructor
     83       /**
     84        *  @brief  Base constructor.
     85        *
     86        *  This ctor is almost never called by the user directly, rather from
     87        *  derived classes' initialization lists, which pass a pointer to
     88        *  their own stream buffer.
     89       */
     90       explicit
     91       basic_istream(__streambuf_type* __sb)
     92       : _M_gcount(streamsize(0))
     93       { this->init(__sb); }
     94 
     95       /**
     96        *  @brief  Base destructor.
     97        *
     98        *  This does very little apart from providing a virtual base dtor.
     99       */
    100       virtual 
    101       ~basic_istream() 
    102       { _M_gcount = streamsize(0); }
    103 
    104       // [27.6.1.1.2] prefix/suffix
    105       class sentry;
    106       friend class sentry;
    107 
    108       // [27.6.1.2] formatted input
    109       // [27.6.1.2.3] basic_istream::operator>>
    110       //@{
    111       /**
    112        *  @brief  Interface for manipulators.
    113        *
    114        *  Manipulators such as @c std::ws and @c std::dec use these
    115        *  functions in constructs like "std::cin >> std::ws".  For more
    116        *  information, see the iomanip header.
    117       */
    118       __istream_type&
    119       operator>>(__istream_type& (*__pf)(__istream_type&))
    120       { return __pf(*this); }
    121 
    122       __istream_type&
    123       operator>>(__ios_type& (*__pf)(__ios_type&))
    124       { 
    125 	__pf(*this);
    126 	return *this;
    127       }
    128 
    129       __istream_type&
    130       operator>>(ios_base& (*__pf)(ios_base&))
    131       {
    132 	__pf(*this);
    133 	return *this;
    134       }
    135       //@}
    136       
    137       // [27.6.1.2.2] arithmetic extractors
    138       /**
    139        *  @name Arithmetic Extractors
    140        *
    141        *  All the @c operator>> functions (aka <em>formatted input
    142        *  functions</em>) have some common behavior.  Each starts by
    143        *  constructing a temporary object of type std::basic_istream::sentry
    144        *  with the second argument (noskipws) set to false.  This has several
    145        *  effects, concluding with the setting of a status flag; see the
    146        *  sentry documentation for more.
    147        *
    148        *  If the sentry status is good, the function tries to extract
    149        *  whatever data is appropriate for the type of the argument.
    150        *
    151        *  If an exception is thrown during extraction, ios_base::badbit
    152        *  will be turned on in the stream's error state without causing an
    153        *  ios_base::failure to be thrown.  The original exception will then
    154        *  be rethrown.
    155       */
    156       //@{
    157       /**
    158        *  @brief  Basic arithmetic extractors
    159        *  @param  A variable of builtin type.
    160        *  @return  @c *this if successful
    161        *
    162        *  These functions use the stream's current locale (specifically, the
    163        *  @c num_get facet) to parse the input data.
    164       */
    165       __istream_type& 
    166       operator>>(bool& __n)
    167       { return _M_extract(__n); }
    168       
    169       __istream_type& 
    170       operator>>(short& __n);
    171       
    172       __istream_type& 
    173       operator>>(unsigned short& __n)
    174       { return _M_extract(__n); }
    175 
    176       __istream_type& 
    177       operator>>(int& __n);
    178     
    179       __istream_type& 
    180       operator>>(unsigned int& __n)
    181       { return _M_extract(__n); }
    182 
    183       __istream_type& 
    184       operator>>(long& __n)
    185       { return _M_extract(__n); }
    186       
    187       __istream_type& 
    188       operator>>(unsigned long& __n)
    189       { return _M_extract(__n); }
    190 
    191 #ifdef _GLIBCXX_USE_LONG_LONG
    192       __istream_type& 
    193       operator>>(long long& __n)
    194       { return _M_extract(__n); }
    195 
    196       __istream_type& 
    197       operator>>(unsigned long long& __n)
    198       { return _M_extract(__n); }
    199 #endif
    200 
    201       __istream_type& 
    202       operator>>(float& __f)
    203       { return _M_extract(__f); }
    204 
    205       __istream_type& 
    206       operator>>(double& __f)
    207       { return _M_extract(__f); }
    208 
    209       __istream_type& 
    210       operator>>(long double& __f)
    211       { return _M_extract(__f); }
    212 
    213       __istream_type& 
    214       operator>>(void*& __p)
    215       { return _M_extract(__p); }
    216 
    217       /**
    218        *  @brief  Extracting into another streambuf.
    219        *  @param  sb  A pointer to a streambuf
    220        *
    221        *  This function behaves like one of the basic arithmetic extractors,
    222        *  in that it also constructs a sentry object and has the same error
    223        *  handling behavior.
    224        *
    225        *  If @a sb is NULL, the stream will set failbit in its error state.
    226        *
    227        *  Characters are extracted from this stream and inserted into the
    228        *  @a sb streambuf until one of the following occurs:
    229        *
    230        *  - the input stream reaches end-of-file,
    231        *  - insertion into the output buffer fails (in this case, the
    232        *    character that would have been inserted is not extracted), or
    233        *  - an exception occurs (and in this case is caught)
    234        *
    235        *  If the function inserts no characters, failbit is set.
    236       */
    237       __istream_type& 
    238       operator>>(__streambuf_type* __sb);
    239       //@}
    240       
    241       // [27.6.1.3] unformatted input
    242       /**
    243        *  @brief  Character counting
    244        *  @return  The number of characters extracted by the previous
    245        *           unformatted input function dispatched for this stream.
    246       */
    247       streamsize 
    248       gcount() const 
    249       { return _M_gcount; }
    250       
    251       /**
    252        *  @name Unformatted Input Functions
    253        *
    254        *  All the unformatted input functions have some common behavior.
    255        *  Each starts by constructing a temporary object of type
    256        *  std::basic_istream::sentry with the second argument (noskipws)
    257        *  set to true.  This has several effects, concluding with the
    258        *  setting of a status flag; see the sentry documentation for more.
    259        *
    260        *  If the sentry status is good, the function tries to extract
    261        *  whatever data is appropriate for the type of the argument.
    262        *
    263        *  The number of characters extracted is stored for later retrieval
    264        *  by gcount().
    265        *
    266        *  If an exception is thrown during extraction, ios_base::badbit
    267        *  will be turned on in the stream's error state without causing an
    268        *  ios_base::failure to be thrown.  The original exception will then
    269        *  be rethrown.
    270       */
    271       //@{
    272       /**
    273        *  @brief  Simple extraction.
    274        *  @return  A character, or eof().
    275        *
    276        *  Tries to extract a character.  If none are available, sets failbit
    277        *  and returns traits::eof().
    278       */
    279       int_type 
    280       get();
    281 
    282       /**
    283        *  @brief  Simple extraction.
    284        *  @param  c  The character in which to store data.
    285        *  @return  *this
    286        *
    287        *  Tries to extract a character and store it in @a c.  If none are
    288        *  available, sets failbit and returns traits::eof().
    289        *
    290        *  @note  This function is not overloaded on signed char and
    291        *         unsigned char.
    292       */
    293       __istream_type& 
    294       get(char_type& __c);
    295 
    296       /**
    297        *  @brief  Simple multiple-character extraction.
    298        *  @param  s  Pointer to an array.
    299        *  @param  n  Maximum number of characters to store in @a s.
    300        *  @param  delim  A "stop" character.
    301        *  @return  *this
    302        *
    303        *  Characters are extracted and stored into @a s until one of the
    304        *  following happens:
    305        *
    306        *  - @c n-1 characters are stored
    307        *  - the input sequence reaches EOF
    308        *  - the next character equals @a delim, in which case the character
    309        *    is not extracted
    310        *
    311        * If no characters are stored, failbit is set in the stream's error
    312        * state.
    313        *
    314        * In any case, a null character is stored into the next location in
    315        * the array.
    316        *
    317        *  @note  This function is not overloaded on signed char and
    318        *         unsigned char.
    319       */
    320       __istream_type& 
    321       get(char_type* __s, streamsize __n, char_type __delim);
    322 
    323       /**
    324        *  @brief  Simple multiple-character extraction.
    325        *  @param  s  Pointer to an array.
    326        *  @param  n  Maximum number of characters to store in @a s.
    327        *  @return  *this
    328        *
    329        *  Returns @c get(s,n,widen('\n')).
    330       */
    331       __istream_type& 
    332       get(char_type* __s, streamsize __n)
    333       { return this->get(__s, __n, this->widen('\n')); }
    334 
    335       /**
    336        *  @brief  Extraction into another streambuf.
    337        *  @param  sb  A streambuf in which to store data.
    338        *  @param  delim  A "stop" character.
    339        *  @return  *this
    340        *
    341        *  Characters are extracted and inserted into @a sb until one of the
    342        *  following happens:
    343        *
    344        *  - the input sequence reaches EOF
    345        *  - insertion into the output buffer fails (in this case, the
    346        *    character that would have been inserted is not extracted)
    347        *  - the next character equals @a delim (in this case, the character
    348        *    is not extracted)
    349        *  - an exception occurs (and in this case is caught)
    350        *
    351        * If no characters are stored, failbit is set in the stream's error
    352        * state.
    353       */
    354       __istream_type&
    355       get(__streambuf_type& __sb, char_type __delim);
    356 
    357       /**
    358        *  @brief  Extraction into another streambuf.
    359        *  @param  sb  A streambuf in which to store data.
    360        *  @return  *this
    361        *
    362        *  Returns @c get(sb,widen('\n')).
    363       */
    364       __istream_type&
    365       get(__streambuf_type& __sb)
    366       { return this->get(__sb, this->widen('\n')); }
    367 
    368       /**
    369        *  @brief  String extraction.
    370        *  @param  s  A character array in which to store the data.
    371        *  @param  n  Maximum number of characters to extract.
    372        *  @param  delim  A "stop" character.
    373        *  @return  *this
    374        *
    375        *  Extracts and stores characters into @a s until one of the
    376        *  following happens.  Note that these criteria are required to be
    377        *  tested in the order listed here, to allow an input line to exactly
    378        *  fill the @a s array without setting failbit.
    379        *
    380        *  -# the input sequence reaches end-of-file, in which case eofbit
    381        *     is set in the stream error state
    382        *  -# the next character equals @c delim, in which case the character
    383        *     is extracted (and therefore counted in @c gcount()) but not stored
    384        *  -# @c n-1 characters are stored, in which case failbit is set
    385        *     in the stream error state
    386        *
    387        *  If no characters are extracted, failbit is set.  (An empty line of
    388        *  input should therefore not cause failbit to be set.)
    389        *
    390        *  In any case, a null character is stored in the next location in
    391        *  the array.
    392       */
    393       __istream_type& 
    394       getline(char_type* __s, streamsize __n, char_type __delim);
    395 
    396       /**
    397        *  @brief  String extraction.
    398        *  @param  s  A character array in which to store the data.
    399        *  @param  n  Maximum number of characters to extract.
    400        *  @return  *this
    401        *
    402        *  Returns @c getline(s,n,widen('\n')).
    403       */
    404       __istream_type& 
    405       getline(char_type* __s, streamsize __n)
    406       { return this->getline(__s, __n, this->widen('\n')); }
    407 
    408       /**
    409        *  @brief  Discarding characters
    410        *  @param  n  Number of characters to discard.
    411        *  @param  delim  A "stop" character.
    412        *  @return  *this
    413        *
    414        *  Extracts characters and throws them away until one of the
    415        *  following happens:
    416        *  - if @a n @c != @c std::numeric_limits<int>::max(), @a n
    417        *    characters are extracted
    418        *  - the input sequence reaches end-of-file
    419        *  - the next character equals @a delim (in this case, the character
    420        *    is extracted); note that this condition will never occur if
    421        *    @a delim equals @c traits::eof().
    422        *
    423        *  NB: Provide three overloads, instead of the single function
    424        *  (with defaults) mandated by the Standard: this leads to a
    425        *  better performing implementation, while still conforming to
    426        *  the Standard.
    427       */
    428       __istream_type& 
    429       ignore();
    430 
    431       __istream_type& 
    432       ignore(streamsize __n);
    433 
    434       __istream_type& 
    435       ignore(streamsize __n, int_type __delim);
    436       
    437       /**
    438        *  @brief  Looking ahead in the stream
    439        *  @return  The next character, or eof().
    440        *
    441        *  If, after constructing the sentry object, @c good() is false,
    442        *  returns @c traits::eof().  Otherwise reads but does not extract
    443        *  the next input character.
    444       */
    445       int_type 
    446       peek();
    447       
    448       /**
    449        *  @brief  Extraction without delimiters.
    450        *  @param  s  A character array.
    451        *  @param  n  Maximum number of characters to store.
    452        *  @return  *this
    453        *
    454        *  If the stream state is @c good(), extracts characters and stores
    455        *  them into @a s until one of the following happens:
    456        *  - @a n characters are stored
    457        *  - the input sequence reaches end-of-file, in which case the error
    458        *    state is set to @c failbit|eofbit.
    459        *
    460        *  @note  This function is not overloaded on signed char and
    461        *         unsigned char.
    462       */
    463       __istream_type& 
    464       read(char_type* __s, streamsize __n);
    465 
    466       /**
    467        *  @brief  Extraction until the buffer is exhausted, but no more.
    468        *  @param  s  A character array.
    469        *  @param  n  Maximum number of characters to store.
    470        *  @return  The number of characters extracted.
    471        *
    472        *  Extracts characters and stores them into @a s depending on the
    473        *  number of characters remaining in the streambuf's buffer,
    474        *  @c rdbuf()->in_avail(), called @c A here:
    475        *  - if @c A @c == @c -1, sets eofbit and extracts no characters
    476        *  - if @c A @c == @c 0, extracts no characters
    477        *  - if @c A @c > @c 0, extracts @c min(A,n)
    478        *
    479        *  The goal is to empty the current buffer, and to not request any
    480        *  more from the external input sequence controlled by the streambuf.
    481       */
    482       streamsize 
    483       readsome(char_type* __s, streamsize __n);
    484       
    485       /**
    486        *  @brief  Unextracting a single character.
    487        *  @param  c  The character to push back into the input stream.
    488        *  @return  *this
    489        *
    490        *  If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
    491        *
    492        *  If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
    493        *  the error state.
    494        *
    495        *  @note  Since no characters are extracted, the next call to
    496        *         @c gcount() will return 0, as required by DR 60.
    497       */
    498       __istream_type& 
    499       putback(char_type __c);
    500 
    501       /**
    502        *  @brief  Unextracting the previous character.
    503        *  @return  *this
    504        *
    505        *  If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
    506        *
    507        *  If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
    508        *  the error state.
    509        *
    510        *  @note  Since no characters are extracted, the next call to
    511        *         @c gcount() will return 0, as required by DR 60.
    512       */
    513       __istream_type& 
    514       unget();
    515 
    516       /**
    517        *  @brief  Synchronizing the stream buffer.
    518        *  @return  0 on success, -1 on failure
    519        *
    520        *  If @c rdbuf() is a null pointer, returns -1.
    521        *
    522        *  Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
    523        *  sets badbit and returns -1.
    524        *
    525        *  Otherwise, returns 0.
    526        *
    527        *  @note  This function does not count the number of characters
    528        *         extracted, if any, and therefore does not affect the next
    529        *         call to @c gcount().
    530       */
    531       int 
    532       sync();
    533 
    534       /**
    535        *  @brief  Getting the current read position.
    536        *  @return  A file position object.
    537        *
    538        *  If @c fail() is not false, returns @c pos_type(-1) to indicate
    539        *  failure.  Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
    540        *
    541        *  @note  This function does not count the number of characters
    542        *         extracted, if any, and therefore does not affect the next
    543        *         call to @c gcount().
    544       */
    545       pos_type 
    546       tellg();
    547 
    548       /**
    549        *  @brief  Changing the current read position.
    550        *  @param  pos  A file position object.
    551        *  @return  *this
    552        *
    553        *  If @c fail() is not true, calls @c rdbuf()->pubseekpos(pos).  If
    554        *  that function fails, sets failbit.
    555        *
    556        *  @note  This function does not count the number of characters
    557        *         extracted, if any, and therefore does not affect the next
    558        *         call to @c gcount().
    559       */
    560       __istream_type& 
    561       seekg(pos_type);
    562 
    563       /**
    564        *  @brief  Changing the current read position.
    565        *  @param  off  A file offset object.
    566        *  @param  dir  The direction in which to seek.
    567        *  @return  *this
    568        *
    569        *  If @c fail() is not true, calls @c rdbuf()->pubseekoff(off,dir).
    570        *  If that function fails, sets failbit.
    571        *
    572        *  @note  This function does not count the number of characters
    573        *         extracted, if any, and therefore does not affect the next
    574        *         call to @c gcount().
    575       */
    576       __istream_type& 
    577       seekg(off_type, ios_base::seekdir);
    578       //@}
    579 
    580     protected:
    581       basic_istream()
    582       : _M_gcount(streamsize(0))
    583       { this->init(0); }
    584 
    585       template<typename _ValueT>
    586         __istream_type&
    587         _M_extract(_ValueT& __v);
    588     };
    589 
    590   // Explicit specialization declarations, defined in src/istream.cc.
    591   template<> 
    592     basic_istream<char>& 
    593     basic_istream<char>::
    594     getline(char_type* __s, streamsize __n, char_type __delim);
    595   
    596   template<>
    597     basic_istream<char>&
    598     basic_istream<char>::
    599     ignore(streamsize __n);
    600   
    601   template<>
    602     basic_istream<char>&
    603     basic_istream<char>::
    604     ignore(streamsize __n, int_type __delim);
    605 
    606 #ifdef _GLIBCXX_USE_WCHAR_T
    607   template<> 
    608     basic_istream<wchar_t>& 
    609     basic_istream<wchar_t>::
    610     getline(char_type* __s, streamsize __n, char_type __delim);
    611 
    612   template<>
    613     basic_istream<wchar_t>&
    614     basic_istream<wchar_t>::
    615     ignore(streamsize __n);
    616   
    617   template<>
    618     basic_istream<wchar_t>&
    619     basic_istream<wchar_t>::
    620     ignore(streamsize __n, int_type __delim);
    621 #endif
    622 
    623   /**
    624    *  @brief  Performs setup work for input streams.
    625    *
    626    *  Objects of this class are created before all of the standard
    627    *  extractors are run.  It is responsible for "exception-safe prefix and
    628    *  suffix operations," although only prefix actions are currently required
    629    *  by the standard. 
    630   */
    631   template<typename _CharT, typename _Traits>
    632     class basic_istream<_CharT, _Traits>::sentry
    633     {
    634     public:
    635       /// Easy access to dependant types.
    636       typedef _Traits 					traits_type;
    637       typedef basic_streambuf<_CharT, _Traits> 		__streambuf_type;
    638       typedef basic_istream<_CharT, _Traits> 		__istream_type;
    639       typedef typename __istream_type::__ctype_type 	__ctype_type;
    640       typedef typename _Traits::int_type		__int_type;
    641 
    642       /**
    643        *  @brief  The constructor performs all the work.
    644        *  @param  is  The input stream to guard.
    645        *  @param  noskipws  Whether to consume whitespace or not.
    646        *
    647        *  If the stream state is good (@a is.good() is true), then the
    648        *  following actions are performed, otherwise the sentry state is
    649        *  false ("not okay") and failbit is set in the stream state.
    650        *
    651        *  The sentry's preparatory actions are:
    652        *
    653        *  -# if the stream is tied to an output stream, @c is.tie()->flush()
    654        *     is called to synchronize the output sequence
    655        *  -# if @a noskipws is false, and @c ios_base::skipws is set in
    656        *     @c is.flags(), the sentry extracts and discards whitespace
    657        *     characters from the stream.  The currently imbued locale is
    658        *     used to determine whether each character is whitespace.
    659        *
    660        *  If the stream state is still good, then the sentry state becomes
    661        *  true ("okay").
    662       */
    663       explicit
    664       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
    665 
    666       /**
    667        *  @brief  Quick status checking.
    668        *  @return  The sentry state.
    669        *
    670        *  For ease of use, sentries may be converted to booleans.  The
    671        *  return value is that of the sentry state (true == okay).
    672       */
    673       operator bool() const
    674       { return _M_ok; }
    675 
    676     private:
    677       bool _M_ok;
    678     };
    679 
    680   // [27.6.1.2.3] character extraction templates
    681   //@{
    682   /**
    683    *  @brief  Character extractors
    684    *  @param  in  An input stream.
    685    *  @param  c  A character reference.
    686    *  @return  in
    687    *
    688    *  Behaves like one of the formatted arithmetic extractors described in
    689    *  std::basic_istream.  After constructing a sentry object with good
    690    *  status, this function extracts a character (if one is available) and
    691    *  stores it in @a c.  Otherwise, sets failbit in the input stream.
    692   */
    693   template<typename _CharT, typename _Traits>
    694     basic_istream<_CharT, _Traits>&
    695     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
    696 
    697   template<class _Traits>
    698     inline basic_istream<char, _Traits>&
    699     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
    700     { return (__in >> reinterpret_cast<char&>(__c)); }
    701 
    702   template<class _Traits>
    703     inline basic_istream<char, _Traits>&
    704     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
    705     { return (__in >> reinterpret_cast<char&>(__c)); }
    706   //@}
    707 
    708   //@{
    709   /**
    710    *  @brief  Character string extractors
    711    *  @param  in  An input stream.
    712    *  @param  s  A pointer to a character array.
    713    *  @return  in
    714    *
    715    *  Behaves like one of the formatted arithmetic extractors described in
    716    *  std::basic_istream.  After constructing a sentry object with good
    717    *  status, this function extracts up to @c n characters and stores them
    718    *  into the array starting at @a s.  @c n is defined as:
    719    *
    720    *  - if @c width() is greater than zero, @c n is width()
    721    *  - otherwise @c n is "the number of elements of the largest array of
    722    *    @c char_type that can store a terminating @c eos." [27.6.1.2.3]/6
    723    *
    724    *  Characters are extracted and stored until one of the following happens:
    725    *  - @c n-1 characters are stored
    726    *  - EOF is reached
    727    *  - the next character is whitespace according to the current locale
    728    *  - the next character is a null byte (i.e., @c charT() )
    729    *
    730    *  @c width(0) is then called for the input stream.
    731    *
    732    *  If no characters are extracted, sets failbit.
    733   */
    734   template<typename _CharT, typename _Traits>
    735     basic_istream<_CharT, _Traits>&
    736     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
    737 
    738   // Explicit specialization declaration, defined in src/istream.cc.
    739   template<>
    740     basic_istream<char>&
    741     operator>>(basic_istream<char>& __in, char* __s);
    742 
    743   template<class _Traits>
    744     inline basic_istream<char, _Traits>&
    745     operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
    746     { return (__in >> reinterpret_cast<char*>(__s)); }
    747 
    748   template<class _Traits>
    749     inline basic_istream<char, _Traits>&
    750     operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
    751     { return (__in >> reinterpret_cast<char*>(__s)); }
    752   //@}
    753 
    754   // 27.6.1.5 Template class basic_iostream
    755   /**
    756    *  @brief  Merging istream and ostream capabilities.
    757    *  @ingroup io
    758    *
    759    *  This class multiply inherits from the input and output stream classes
    760    *  simply to provide a single interface.
    761   */
    762   template<typename _CharT, typename _Traits>
    763     class basic_iostream
    764     : public basic_istream<_CharT, _Traits>, 
    765       public basic_ostream<_CharT, _Traits>
    766     {
    767     public:
    768       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    769       // 271. basic_iostream missing typedefs
    770       // Types (inherited):
    771       typedef _CharT                     		char_type;
    772       typedef typename _Traits::int_type 		int_type;
    773       typedef typename _Traits::pos_type 		pos_type;
    774       typedef typename _Traits::off_type 		off_type;
    775       typedef _Traits                    		traits_type;
    776 
    777       // Non-standard Types:
    778       typedef basic_istream<_CharT, _Traits>		__istream_type;
    779       typedef basic_ostream<_CharT, _Traits>		__ostream_type;
    780 
    781       /**
    782        *  @brief  Constructor does nothing.
    783        *
    784        *  Both of the parent classes are initialized with the same
    785        *  streambuf pointer passed to this constructor.
    786       */
    787       explicit
    788       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
    789       : __istream_type(__sb), __ostream_type(__sb) { }
    790 
    791       /**
    792        *  @brief  Destructor does nothing.
    793       */
    794       virtual 
    795       ~basic_iostream() { }
    796 
    797     protected:
    798       basic_iostream()
    799       : __istream_type(), __ostream_type() { }
    800     };
    801 
    802   // [27.6.1.4] standard basic_istream manipulators
    803   /**
    804    *  @brief  Quick and easy way to eat whitespace
    805    *
    806    *  This manipulator extracts whitespace characters, stopping when the
    807    *  next character is non-whitespace, or when the input sequence is empty.
    808    *  If the sequence is empty, @c eofbit is set in the stream, but not
    809    *  @c failbit.
    810    *
    811    *  The current locale is used to distinguish whitespace characters.
    812    *
    813    *  Example:
    814    *  @code
    815    *     MyClass   mc;
    816    *
    817    *     std::cin >> std::ws >> mc;
    818    *  @endcode
    819    *  will skip leading whitespace before calling operator>> on cin and your
    820    *  object.  Note that the same effect can be achieved by creating a
    821    *  std::basic_istream::sentry inside your definition of operator>>.
    822   */
    823   template<typename _CharT, typename _Traits>
    824     basic_istream<_CharT, _Traits>& 
    825     ws(basic_istream<_CharT, _Traits>& __is);
    826 
    827 _GLIBCXX_END_NAMESPACE
    828 
    829 #ifndef _GLIBCXX_EXPORT_TEMPLATE
    830 # include <bits/istream.tcc>
    831 #endif
    832 
    833 #endif	/* _GLIBCXX_ISTREAM */
    834