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