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

Generated on Tue Apr 21 13:13:28 2009 for libstdc++ by  doxygen 1.5.8