libstdc++
istream
Go to the documentation of this file.
00001 // Input streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
00004 // 2006, 2007, 2008, 2009, 2010, 2011, 2012
00005 // Free Software Foundation, Inc.
00006 //
00007 // This file is part of the GNU ISO C++ Library.  This library is free
00008 // software; you can redistribute it and/or modify it under the
00009 // terms of the GNU General Public License as published by the
00010 // Free Software Foundation; either version 3, or (at your option)
00011 // any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 // Under Section 7 of GPL version 3, you are granted additional
00019 // permissions described in the GCC Runtime Library Exception, version
00020 // 3.1, as published by the Free Software Foundation.
00021 
00022 // You should have received a copy of the GNU General Public License and
00023 // a copy of the GCC Runtime Library Exception along with this program;
00024 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00025 // <http://www.gnu.org/licenses/>.
00026 
00027 //
00028 // ISO C++ 14882: 27.6.1  Input streams
00029 //
00030 
00031 /** @file include/istream
00032  *  This is a Standard C++ Library header.
00033  */
00034 
00035 #ifndef _GLIBCXX_ISTREAM
00036 #define _GLIBCXX_ISTREAM 1
00037 
00038 #pragma GCC system_header
00039 
00040 #include <ios>
00041 #include <ostream>
00042 
00043 namespace std _GLIBCXX_VISIBILITY(default)
00044 {
00045 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00046 
00047   /**
00048    *  @brief  Template class basic_istream.
00049    *  @ingroup io
00050    *
00051    *  @tparam _CharT  Type of character stream.
00052    *  @tparam _Traits  Traits for character type, defaults to
00053    *                   char_traits<_CharT>.
00054    *
00055    *  This is the base class for all input streams.  It provides text
00056    *  formatting of all builtin types, and communicates with any class
00057    *  derived from basic_streambuf to do the actual input.
00058   */
00059   template<typename _CharT, typename _Traits>
00060     class basic_istream : virtual public basic_ios<_CharT, _Traits>
00061     {
00062     public:
00063       // Types (inherited from basic_ios (27.4.4)):
00064       typedef _CharT                    char_type;
00065       typedef typename _Traits::int_type        int_type;
00066       typedef typename _Traits::pos_type        pos_type;
00067       typedef typename _Traits::off_type        off_type;
00068       typedef _Traits                   traits_type;
00069 
00070       // Non-standard Types:
00071       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00072       typedef basic_ios<_CharT, _Traits>        __ios_type;
00073       typedef basic_istream<_CharT, _Traits>        __istream_type;
00074       typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
00075                             __num_get_type;
00076       typedef ctype<_CharT>                 __ctype_type;
00077 
00078     protected:
00079       // Data Members:
00080       /**
00081        *  The number of characters extracted in the previous unformatted
00082        *  function; see gcount().
00083       */
00084       streamsize        _M_gcount;
00085 
00086     public:
00087       /**
00088        *  @brief  Base constructor.
00089        *
00090        *  This ctor is almost never called by the user directly, rather from
00091        *  derived classes' initialization lists, which pass a pointer to
00092        *  their own stream buffer.
00093       */
00094       explicit
00095       basic_istream(__streambuf_type* __sb)
00096       : _M_gcount(streamsize(0))
00097       { this->init(__sb); }
00098 
00099       /**
00100        *  @brief  Base destructor.
00101        *
00102        *  This does very little apart from providing a virtual base dtor.
00103       */
00104       virtual
00105       ~basic_istream()
00106       { _M_gcount = streamsize(0); }
00107 
00108       /// Safe prefix/suffix operations.
00109       class sentry;
00110       friend class sentry;
00111 
00112       //@{
00113       /**
00114        *  @brief  Interface for manipulators.
00115        *
00116        *  Manipulators such as @c std::ws and @c std::dec use these
00117        *  functions in constructs like
00118        *  <code>std::cin >> std::ws</code>.
00119        *  For more information, see the iomanip header.
00120       */
00121       __istream_type&
00122       operator>>(__istream_type& (*__pf)(__istream_type&))
00123       { return __pf(*this); }
00124 
00125       __istream_type&
00126       operator>>(__ios_type& (*__pf)(__ios_type&))
00127       {
00128     __pf(*this);
00129     return *this;
00130       }
00131 
00132       __istream_type&
00133       operator>>(ios_base& (*__pf)(ios_base&))
00134       {
00135     __pf(*this);
00136     return *this;
00137       }
00138       //@}
00139 
00140       //@{
00141       /**
00142        *  @name Extractors
00143        *
00144        *  All the @c operator>> functions (aka <em>formatted input
00145        *  functions</em>) have some common behavior.  Each starts by
00146        *  constructing a temporary object of type std::basic_istream::sentry
00147        *  with the second argument (noskipws) set to false.  This has several
00148        *  effects, concluding with the setting of a status flag; see the
00149        *  sentry documentation for more.
00150        *
00151        *  If the sentry status is good, the function tries to extract
00152        *  whatever data is appropriate for the type of the argument.
00153        *
00154        *  If an exception is thrown during extraction, ios_base::badbit
00155        *  will be turned on in the stream's error state without causing an
00156        *  ios_base::failure to be thrown.  The original exception will then
00157        *  be rethrown.
00158       */
00159 
00160       //@{
00161       /**
00162        *  @brief  Integer arithmetic extractors
00163        *  @param  __n A variable of builtin integral type.
00164        *  @return  @c *this if successful
00165        *
00166        *  These functions use the stream's current locale (specifically, the
00167        *  @c num_get facet) to parse the input data.
00168       */
00169       __istream_type&
00170       operator>>(bool& __n)
00171       { return _M_extract(__n); }
00172 
00173       __istream_type&
00174       operator>>(short& __n);
00175 
00176       __istream_type&
00177       operator>>(unsigned short& __n)
00178       { return _M_extract(__n); }
00179 
00180       __istream_type&
00181       operator>>(int& __n);
00182 
00183       __istream_type&
00184       operator>>(unsigned int& __n)
00185       { return _M_extract(__n); }
00186 
00187       __istream_type&
00188       operator>>(long& __n)
00189       { return _M_extract(__n); }
00190 
00191       __istream_type&
00192       operator>>(unsigned long& __n)
00193       { return _M_extract(__n); }
00194 
00195 #ifdef _GLIBCXX_USE_LONG_LONG
00196       __istream_type&
00197       operator>>(long long& __n)
00198       { return _M_extract(__n); }
00199 
00200       __istream_type&
00201       operator>>(unsigned long long& __n)
00202       { return _M_extract(__n); }
00203 #endif
00204       //@}
00205 
00206       //@{
00207       /**
00208        *  @brief  Floating point arithmetic extractors
00209        *  @param  __f A variable of builtin floating point type.
00210        *  @return  @c *this if successful
00211        *
00212        *  These functions use the stream's current locale (specifically, the
00213        *  @c num_get facet) to parse the input data.
00214       */
00215       __istream_type&
00216       operator>>(float& __f)
00217       { return _M_extract(__f); }
00218 
00219       __istream_type&
00220       operator>>(double& __f)
00221       { return _M_extract(__f); }
00222 
00223       __istream_type&
00224       operator>>(long double& __f)
00225       { return _M_extract(__f); }
00226       //@}
00227 
00228       /**
00229        *  @brief  Basic arithmetic extractors
00230        *  @param  __p A variable of pointer type.
00231        *  @return  @c *this if successful
00232        *
00233        *  These functions use the stream's current locale (specifically, the
00234        *  @c num_get facet) to parse the input data.
00235       */
00236       __istream_type&
00237       operator>>(void*& __p)
00238       { return _M_extract(__p); }
00239 
00240       /**
00241        *  @brief  Extracting into another streambuf.
00242        *  @param  __sb  A pointer to a streambuf
00243        *
00244        *  This function behaves like one of the basic arithmetic extractors,
00245        *  in that it also constructs a sentry object and has the same error
00246        *  handling behavior.
00247        *
00248        *  If @p __sb is NULL, the stream will set failbit in its error state.
00249        *
00250        *  Characters are extracted from this stream and inserted into the
00251        *  @p __sb streambuf until one of the following occurs:
00252        *
00253        *  - the input stream reaches end-of-file,
00254        *  - insertion into the output buffer fails (in this case, the
00255        *    character that would have been inserted is not extracted), or
00256        *  - an exception occurs (and in this case is caught)
00257        *
00258        *  If the function inserts no characters, failbit is set.
00259       */
00260       __istream_type&
00261       operator>>(__streambuf_type* __sb);
00262       //@}
00263 
00264       // [27.6.1.3] unformatted input
00265       /**
00266        *  @brief  Character counting
00267        *  @return  The number of characters extracted by the previous
00268        *           unformatted input function dispatched for this stream.
00269       */
00270       streamsize
00271       gcount() const
00272       { return _M_gcount; }
00273 
00274       //@{
00275       /**
00276        *  @name Unformatted Input Functions
00277        *
00278        *  All the unformatted input functions have some common behavior.
00279        *  Each starts by constructing a temporary object of type
00280        *  std::basic_istream::sentry with the second argument (noskipws)
00281        *  set to true.  This has several effects, concluding with the
00282        *  setting of a status flag; see the sentry documentation for more.
00283        *
00284        *  If the sentry status is good, the function tries to extract
00285        *  whatever data is appropriate for the type of the argument.
00286        *
00287        *  The number of characters extracted is stored for later retrieval
00288        *  by gcount().
00289        *
00290        *  If an exception is thrown during extraction, ios_base::badbit
00291        *  will be turned on in the stream's error state without causing an
00292        *  ios_base::failure to be thrown.  The original exception will then
00293        *  be rethrown.
00294       */
00295 
00296       /**
00297        *  @brief  Simple extraction.
00298        *  @return  A character, or eof().
00299        *
00300        *  Tries to extract a character.  If none are available, sets failbit
00301        *  and returns traits::eof().
00302       */
00303       int_type
00304       get();
00305 
00306       /**
00307        *  @brief  Simple extraction.
00308        *  @param  __c  The character in which to store data.
00309        *  @return  *this
00310        *
00311        *  Tries to extract a character and store it in @a __c.  If none are
00312        *  available, sets failbit and returns traits::eof().
00313        *
00314        *  @note  This function is not overloaded on signed char and
00315        *         unsigned char.
00316       */
00317       __istream_type&
00318       get(char_type& __c);
00319 
00320       /**
00321        *  @brief  Simple multiple-character extraction.
00322        *  @param  __s  Pointer to an array.
00323        *  @param  __n  Maximum number of characters to store in @a __s.
00324        *  @param  __delim  A "stop" character.
00325        *  @return  *this
00326        *
00327        *  Characters are extracted and stored into @a __s until one of the
00328        *  following happens:
00329        *
00330        *  - @c __n-1 characters are stored
00331        *  - the input sequence reaches EOF
00332        *  - the next character equals @a __delim, in which case the character
00333        *    is not extracted
00334        *
00335        * If no characters are stored, failbit is set in the stream's error
00336        * state.
00337        *
00338        * In any case, a null character is stored into the next location in
00339        * the array.
00340        *
00341        *  @note  This function is not overloaded on signed char and
00342        *         unsigned char.
00343       */
00344       __istream_type&
00345       get(char_type* __s, streamsize __n, char_type __delim);
00346 
00347       /**
00348        *  @brief  Simple multiple-character extraction.
00349        *  @param  __s  Pointer to an array.
00350        *  @param  __n  Maximum number of characters to store in @a s.
00351        *  @return  *this
00352        *
00353        *  Returns @c get(__s,__n,widen(&apos;\\n&apos;)).
00354       */
00355       __istream_type&
00356       get(char_type* __s, streamsize __n)
00357       { return this->get(__s, __n, this->widen('\n')); }
00358 
00359       /**
00360        *  @brief  Extraction into another streambuf.
00361        *  @param  __sb  A streambuf in which to store data.
00362        *  @param  __delim  A "stop" character.
00363        *  @return  *this
00364        *
00365        *  Characters are extracted and inserted into @a __sb until one of the
00366        *  following happens:
00367        *
00368        *  - the input sequence reaches EOF
00369        *  - insertion into the output buffer fails (in this case, the
00370        *    character that would have been inserted is not extracted)
00371        *  - the next character equals @a __delim (in this case, the character
00372        *    is not extracted)
00373        *  - an exception occurs (and in this case is caught)
00374        *
00375        * If no characters are stored, failbit is set in the stream's error
00376        * state.
00377       */
00378       __istream_type&
00379       get(__streambuf_type& __sb, char_type __delim);
00380 
00381       /**
00382        *  @brief  Extraction into another streambuf.
00383        *  @param  __sb  A streambuf in which to store data.
00384        *  @return  *this
00385        *
00386        *  Returns @c get(__sb,widen(&apos;\\n&apos;)).
00387       */
00388       __istream_type&
00389       get(__streambuf_type& __sb)
00390       { return this->get(__sb, this->widen('\n')); }
00391 
00392       /**
00393        *  @brief  String extraction.
00394        *  @param  __s  A character array in which to store the data.
00395        *  @param  __n  Maximum number of characters to extract.
00396        *  @param  __delim  A "stop" character.
00397        *  @return  *this
00398        *
00399        *  Extracts and stores characters into @a __s until one of the
00400        *  following happens.  Note that these criteria are required to be
00401        *  tested in the order listed here, to allow an input line to exactly
00402        *  fill the @a __s array without setting failbit.
00403        *
00404        *  -# the input sequence reaches end-of-file, in which case eofbit
00405        *     is set in the stream error state
00406        *  -# the next character equals @c __delim, in which case the character
00407        *     is extracted (and therefore counted in @c gcount()) but not stored
00408        *  -# @c __n-1 characters are stored, in which case failbit is set
00409        *     in the stream error state
00410        *
00411        *  If no characters are extracted, failbit is set.  (An empty line of
00412        *  input should therefore not cause failbit to be set.)
00413        *
00414        *  In any case, a null character is stored in the next location in
00415        *  the array.
00416       */
00417       __istream_type&
00418       getline(char_type* __s, streamsize __n, char_type __delim);
00419 
00420       /**
00421        *  @brief  String extraction.
00422        *  @param  __s  A character array in which to store the data.
00423        *  @param  __n  Maximum number of characters to extract.
00424        *  @return  *this
00425        *
00426        *  Returns @c getline(__s,__n,widen(&apos;\\n&apos;)).
00427       */
00428       __istream_type&
00429       getline(char_type* __s, streamsize __n)
00430       { return this->getline(__s, __n, this->widen('\n')); }
00431 
00432       /**
00433        *  @brief  Discarding characters
00434        *  @param  __n  Number of characters to discard.
00435        *  @param  __delim  A "stop" character.
00436        *  @return  *this
00437        *
00438        *  Extracts characters and throws them away until one of the
00439        *  following happens:
00440        *  - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
00441        *    characters are extracted
00442        *  - the input sequence reaches end-of-file
00443        *  - the next character equals @a __delim (in this case, the character
00444        *    is extracted); note that this condition will never occur if
00445        *    @a __delim equals @c traits::eof().
00446        *
00447        *  NB: Provide three overloads, instead of the single function
00448        *  (with defaults) mandated by the Standard: this leads to a
00449        *  better performing implementation, while still conforming to
00450        *  the Standard.
00451       */
00452       __istream_type&
00453       ignore(streamsize __n, int_type __delim);
00454 
00455       __istream_type&
00456       ignore(streamsize __n);
00457 
00458       __istream_type&
00459       ignore();
00460 
00461       /**
00462        *  @brief  Looking ahead in the stream
00463        *  @return  The next character, or eof().
00464        *
00465        *  If, after constructing the sentry object, @c good() is false,
00466        *  returns @c traits::eof().  Otherwise reads but does not extract
00467        *  the next input character.
00468       */
00469       int_type
00470       peek();
00471 
00472       /**
00473        *  @brief  Extraction without delimiters.
00474        *  @param  __s  A character array.
00475        *  @param  __n  Maximum number of characters to store.
00476        *  @return  *this
00477        *
00478        *  If the stream state is @c good(), extracts characters and stores
00479        *  them into @a __s until one of the following happens:
00480        *  - @a __n characters are stored
00481        *  - the input sequence reaches end-of-file, in which case the error
00482        *    state is set to @c failbit|eofbit.
00483        *
00484        *  @note  This function is not overloaded on signed char and
00485        *         unsigned char.
00486       */
00487       __istream_type&
00488       read(char_type* __s, streamsize __n);
00489 
00490       /**
00491        *  @brief  Extraction until the buffer is exhausted, but no more.
00492        *  @param  __s  A character array.
00493        *  @param  __n  Maximum number of characters to store.
00494        *  @return  The number of characters extracted.
00495        *
00496        *  Extracts characters and stores them into @a __s depending on the
00497        *  number of characters remaining in the streambuf's buffer,
00498        *  @c rdbuf()->in_avail(), called @c A here:
00499        *  - if @c A @c == @c -1, sets eofbit and extracts no characters
00500        *  - if @c A @c == @c 0, extracts no characters
00501        *  - if @c A @c > @c 0, extracts @c min(A,n)
00502        *
00503        *  The goal is to empty the current buffer, and to not request any
00504        *  more from the external input sequence controlled by the streambuf.
00505       */
00506       streamsize
00507       readsome(char_type* __s, streamsize __n);
00508 
00509       /**
00510        *  @brief  Unextracting a single character.
00511        *  @param  __c  The character to push back into the input stream.
00512        *  @return  *this
00513        *
00514        *  If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
00515        *
00516        *  If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
00517        *  the error state.
00518        *
00519        *  @note  This function first clears eofbit.  Since no characters
00520        *         are extracted, the next call to @c gcount() will return 0,
00521        *         as required by DR 60.
00522       */
00523       __istream_type&
00524       putback(char_type __c);
00525 
00526       /**
00527        *  @brief  Unextracting the previous character.
00528        *  @return  *this
00529        *
00530        *  If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
00531        *
00532        *  If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
00533        *  the error state.
00534        *
00535        *  @note  This function first clears eofbit.  Since no characters
00536        *         are extracted, the next call to @c gcount() will return 0,
00537        *         as required by DR 60.
00538       */
00539       __istream_type&
00540       unget();
00541 
00542       /**
00543        *  @brief  Synchronizing the stream buffer.
00544        *  @return  0 on success, -1 on failure
00545        *
00546        *  If @c rdbuf() is a null pointer, returns -1.
00547        *
00548        *  Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
00549        *  sets badbit and returns -1.
00550        *
00551        *  Otherwise, returns 0.
00552        *
00553        *  @note  This function does not count the number of characters
00554        *         extracted, if any, and therefore does not affect the next
00555        *         call to @c gcount().
00556       */
00557       int
00558       sync();
00559 
00560       /**
00561        *  @brief  Getting the current read position.
00562        *  @return  A file position object.
00563        *
00564        *  If @c fail() is not false, returns @c pos_type(-1) to indicate
00565        *  failure.  Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
00566        *
00567        *  @note  This function does not count the number of characters
00568        *         extracted, if any, and therefore does not affect the next
00569        *         call to @c gcount().  At variance with putback, unget and
00570        *         seekg, eofbit is not cleared first.
00571       */
00572       pos_type
00573       tellg();
00574 
00575       /**
00576        *  @brief  Changing the current read position.
00577        *  @param  __pos  A file position object.
00578        *  @return  *this
00579        *
00580        *  If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos).  If
00581        *  that function fails, sets failbit.
00582        *
00583        *  @note  This function first clears eofbit.  It does not count the
00584        *         number of characters extracted, if any, and therefore does
00585        *         not affect the next call to @c gcount().
00586       */
00587       __istream_type&
00588       seekg(pos_type);
00589 
00590       /**
00591        *  @brief  Changing the current read position.
00592        *  @param  __off  A file offset object.
00593        *  @param  __dir  The direction in which to seek.
00594        *  @return  *this
00595        *
00596        *  If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
00597        *  If that function fails, sets failbit.
00598        *
00599        *  @note  This function first clears eofbit.  It does not count the
00600        *         number of characters extracted, if any, and therefore does
00601        *         not affect the next call to @c gcount().
00602       */
00603       __istream_type&
00604       seekg(off_type, ios_base::seekdir);
00605       //@}
00606 
00607     protected:
00608       basic_istream()
00609       : _M_gcount(streamsize(0))
00610       { this->init(0); }
00611 
00612       template<typename _ValueT>
00613     __istream_type&
00614     _M_extract(_ValueT& __v);
00615     };
00616 
00617   /// Explicit specialization declarations, defined in src/istream.cc.
00618   template<>
00619     basic_istream<char>&
00620     basic_istream<char>::
00621     getline(char_type* __s, streamsize __n, char_type __delim);
00622 
00623   template<>
00624     basic_istream<char>&
00625     basic_istream<char>::
00626     ignore(streamsize __n);
00627 
00628   template<>
00629     basic_istream<char>&
00630     basic_istream<char>::
00631     ignore(streamsize __n, int_type __delim);
00632 
00633 #ifdef _GLIBCXX_USE_WCHAR_T
00634   template<>
00635     basic_istream<wchar_t>&
00636     basic_istream<wchar_t>::
00637     getline(char_type* __s, streamsize __n, char_type __delim);
00638 
00639   template<>
00640     basic_istream<wchar_t>&
00641     basic_istream<wchar_t>::
00642     ignore(streamsize __n);
00643 
00644   template<>
00645     basic_istream<wchar_t>&
00646     basic_istream<wchar_t>::
00647     ignore(streamsize __n, int_type __delim);
00648 #endif
00649 
00650   /**
00651    *  @brief  Performs setup work for input streams.
00652    *
00653    *  Objects of this class are created before all of the standard
00654    *  extractors are run.  It is responsible for <em>exception-safe
00655    *  prefix and suffix operations,</em> although only prefix actions
00656    *  are currently required by the standard.
00657   */
00658   template<typename _CharT, typename _Traits>
00659     class basic_istream<_CharT, _Traits>::sentry
00660     {
00661       // Data Members.
00662       bool _M_ok;
00663 
00664     public:
00665       /// Easy access to dependant types.
00666       typedef _Traits                   traits_type;
00667       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00668       typedef basic_istream<_CharT, _Traits>        __istream_type;
00669       typedef typename __istream_type::__ctype_type     __ctype_type;
00670       typedef typename _Traits::int_type        __int_type;
00671 
00672       /**
00673        *  @brief  The constructor performs all the work.
00674        *  @param  __is  The input stream to guard.
00675        *  @param  __noskipws  Whether to consume whitespace or not.
00676        *
00677        *  If the stream state is good (@a __is.good() is true), then the
00678        *  following actions are performed, otherwise the sentry state
00679        *  is false (<em>not okay</em>) and failbit is set in the
00680        *  stream state.
00681        *
00682        *  The sentry's preparatory actions are:
00683        *
00684        *  -# if the stream is tied to an output stream, @c is.tie()->flush()
00685        *     is called to synchronize the output sequence
00686        *  -# if @a __noskipws is false, and @c ios_base::skipws is set in
00687        *     @c is.flags(), the sentry extracts and discards whitespace
00688        *     characters from the stream.  The currently imbued locale is
00689        *     used to determine whether each character is whitespace.
00690        *
00691        *  If the stream state is still good, then the sentry state becomes
00692        *  true (@a okay).
00693       */
00694       explicit
00695       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00696 
00697       /**
00698        *  @brief  Quick status checking.
00699        *  @return  The sentry state.
00700        *
00701        *  For ease of use, sentries may be converted to booleans.  The
00702        *  return value is that of the sentry state (true == okay).
00703       */
00704 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00705       explicit
00706 #endif
00707       operator bool() const
00708       { return _M_ok; }
00709     };
00710 
00711   //@{
00712   /**
00713    *  @brief  Character extractors
00714    *  @param  __in  An input stream.
00715    *  @param  __c  A character reference.
00716    *  @return  in
00717    *
00718    *  Behaves like one of the formatted arithmetic extractors described in
00719    *  std::basic_istream.  After constructing a sentry object with good
00720    *  status, this function extracts a character (if one is available) and
00721    *  stores it in @a __c.  Otherwise, sets failbit in the input stream.
00722   */
00723   template<typename _CharT, typename _Traits>
00724     basic_istream<_CharT, _Traits>&
00725     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00726 
00727   template<class _Traits>
00728     inline basic_istream<char, _Traits>&
00729     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00730     { return (__in >> reinterpret_cast<char&>(__c)); }
00731 
00732   template<class _Traits>
00733     inline basic_istream<char, _Traits>&
00734     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00735     { return (__in >> reinterpret_cast<char&>(__c)); }
00736   //@}
00737 
00738   //@{
00739   /**
00740    *  @brief  Character string extractors
00741    *  @param  __in  An input stream.
00742    *  @param  __s  A pointer to a character array.
00743    *  @return  __in
00744    *
00745    *  Behaves like one of the formatted arithmetic extractors described in
00746    *  std::basic_istream.  After constructing a sentry object with good
00747    *  status, this function extracts up to @c n characters and stores them
00748    *  into the array starting at @a __s.  @c n is defined as:
00749    *
00750    *  - if @c width() is greater than zero, @c n is width() otherwise
00751    *  - @c n is <em>the number of elements of the largest array of *
00752    *  - @c char_type that can store a terminating @c eos.</em>
00753    *  - [27.6.1.2.3]/6
00754    *
00755    *  Characters are extracted and stored until one of the following happens:
00756    *  - @c n-1 characters are stored
00757    *  - EOF is reached
00758    *  - the next character is whitespace according to the current locale
00759    *  - the next character is a null byte (i.e., @c charT() )
00760    *
00761    *  @c width(0) is then called for the input stream.
00762    *
00763    *  If no characters are extracted, sets failbit.
00764   */
00765   template<typename _CharT, typename _Traits>
00766     basic_istream<_CharT, _Traits>&
00767     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00768 
00769   // Explicit specialization declaration, defined in src/istream.cc.
00770   template<>
00771     basic_istream<char>&
00772     operator>>(basic_istream<char>& __in, char* __s);
00773 
00774   template<class _Traits>
00775     inline basic_istream<char, _Traits>&
00776     operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
00777     { return (__in >> reinterpret_cast<char*>(__s)); }
00778 
00779   template<class _Traits>
00780     inline basic_istream<char, _Traits>&
00781     operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
00782     { return (__in >> reinterpret_cast<char*>(__s)); }
00783   //@}
00784 
00785   /**
00786    *  @brief  Template class basic_iostream
00787    *  @ingroup io
00788    *
00789    *  @tparam _CharT  Type of character stream.
00790    *  @tparam _Traits  Traits for character type, defaults to
00791    *                   char_traits<_CharT>.
00792    *
00793    *  This class multiply inherits from the input and output stream classes
00794    *  simply to provide a single interface.
00795   */
00796   template<typename _CharT, typename _Traits>
00797     class basic_iostream
00798     : public basic_istream<_CharT, _Traits>,
00799       public basic_ostream<_CharT, _Traits>
00800     {
00801     public:
00802       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00803       // 271. basic_iostream missing typedefs
00804       // Types (inherited):
00805       typedef _CharT                    char_type;
00806       typedef typename _Traits::int_type        int_type;
00807       typedef typename _Traits::pos_type        pos_type;
00808       typedef typename _Traits::off_type        off_type;
00809       typedef _Traits                   traits_type;
00810 
00811       // Non-standard Types:
00812       typedef basic_istream<_CharT, _Traits>        __istream_type;
00813       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00814 
00815       /**
00816        *  @brief  Constructor does nothing.
00817        *
00818        *  Both of the parent classes are initialized with the same
00819        *  streambuf pointer passed to this constructor.
00820       */
00821       explicit
00822       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00823       : __istream_type(__sb), __ostream_type(__sb) { }
00824 
00825       /**
00826        *  @brief  Destructor does nothing.
00827       */
00828       virtual
00829       ~basic_iostream() { }
00830 
00831     protected:
00832       basic_iostream()
00833       : __istream_type(), __ostream_type() { }
00834     };
00835 
00836   /**
00837    *  @brief  Quick and easy way to eat whitespace
00838    *
00839    *  This manipulator extracts whitespace characters, stopping when the
00840    *  next character is non-whitespace, or when the input sequence is empty.
00841    *  If the sequence is empty, @c eofbit is set in the stream, but not
00842    *  @c failbit.
00843    *
00844    *  The current locale is used to distinguish whitespace characters.
00845    *
00846    *  Example:
00847    *  @code
00848    *     MyClass   mc;
00849    *
00850    *     std::cin >> std::ws >> mc;
00851    *  @endcode
00852    *  will skip leading whitespace before calling operator>> on cin and your
00853    *  object.  Note that the same effect can be achieved by creating a
00854    *  std::basic_istream::sentry inside your definition of operator>>.
00855   */
00856   template<typename _CharT, typename _Traits>
00857     basic_istream<_CharT, _Traits>&
00858     ws(basic_istream<_CharT, _Traits>& __is);
00859 
00860 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00861   // [27.7.1.6] Rvalue stream extraction
00862   /**
00863    *  @brief  Generic extractor for rvalue stream
00864    *  @param  __is  An input stream.
00865    *  @param  __x  A reference to the extraction target.
00866    *  @return  is
00867    *
00868    *  This is just a forwarding function to allow extraction from
00869    *  rvalue streams since they won't bind to the extractor functions
00870    *  that take an lvalue reference.
00871   */
00872   template<typename _CharT, typename _Traits, typename _Tp>
00873     inline basic_istream<_CharT, _Traits>&
00874     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
00875     { return (__is >> __x); }
00876 #endif // __GXX_EXPERIMENTAL_CXX0X__
00877 
00878 _GLIBCXX_END_NAMESPACE_VERSION
00879 } // namespace
00880 
00881 #include <bits/istream.tcc>
00882 
00883 #endif  /* _GLIBCXX_ISTREAM */