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