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 This function first clears eofbit. Since no characters 00499 * are extracted, the next call to @c gcount() will return 0, 00500 * 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 This function first clears eofbit. Since no characters 00515 * are extracted, the next call to @c gcount() will return 0, 00516 * as required by DR 60. 00517 */ 00518 __istream_type& 00519 unget(); 00520 00521 /** 00522 * @brief Synchronizing the stream buffer. 00523 * @return 0 on success, -1 on failure 00524 * 00525 * If @c rdbuf() is a null pointer, returns -1. 00526 * 00527 * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1, 00528 * sets badbit and returns -1. 00529 * 00530 * Otherwise, returns 0. 00531 * 00532 * @note This function does not count the number of characters 00533 * extracted, if any, and therefore does not affect the next 00534 * call to @c gcount(). 00535 */ 00536 int 00537 sync(); 00538 00539 /** 00540 * @brief Getting the current read position. 00541 * @return A file position object. 00542 * 00543 * If @c fail() is not false, returns @c pos_type(-1) to indicate 00544 * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in). 00545 * 00546 * @note This function does not count the number of characters 00547 * extracted, if any, and therefore does not affect the next 00548 * call to @c gcount(). At variance with putback, unget and 00549 * seekg, eofbit is not cleared first. 00550 */ 00551 pos_type 00552 tellg(); 00553 00554 /** 00555 * @brief Changing the current read position. 00556 * @param pos A file position object. 00557 * @return *this 00558 * 00559 * If @c fail() is not true, calls @c rdbuf()->pubseekpos(pos). If 00560 * that function fails, sets failbit. 00561 * 00562 * @note This function first clears eofbit. It does not count the 00563 * number of characters extracted, if any, and therefore does 00564 * not affect the next call to @c gcount(). 00565 */ 00566 __istream_type& 00567 seekg(pos_type); 00568 00569 /** 00570 * @brief Changing the current read position. 00571 * @param off A file offset object. 00572 * @param dir The direction in which to seek. 00573 * @return *this 00574 * 00575 * If @c fail() is not true, calls @c rdbuf()->pubseekoff(off,dir). 00576 * If that function fails, sets failbit. 00577 * 00578 * @note This function first clears eofbit. It does not count the 00579 * number of characters extracted, if any, and therefore does 00580 * not affect the next call to @c gcount(). 00581 */ 00582 __istream_type& 00583 seekg(off_type, ios_base::seekdir); 00584 //@} 00585 00586 protected: 00587 basic_istream() 00588 : _M_gcount(streamsize(0)) 00589 { this->init(0); } 00590 00591 template<typename _ValueT> 00592 __istream_type& 00593 _M_extract(_ValueT& __v); 00594 }; 00595 00596 // Explicit specialization declarations, defined in src/istream.cc. 00597 template<> 00598 basic_istream<char>& 00599 basic_istream<char>:: 00600 getline(char_type* __s, streamsize __n, char_type __delim); 00601 00602 template<> 00603 basic_istream<char>& 00604 basic_istream<char>:: 00605 ignore(streamsize __n); 00606 00607 template<> 00608 basic_istream<char>& 00609 basic_istream<char>:: 00610 ignore(streamsize __n, int_type __delim); 00611 00612 #ifdef _GLIBCXX_USE_WCHAR_T 00613 template<> 00614 basic_istream<wchar_t>& 00615 basic_istream<wchar_t>:: 00616 getline(char_type* __s, streamsize __n, char_type __delim); 00617 00618 template<> 00619 basic_istream<wchar_t>& 00620 basic_istream<wchar_t>:: 00621 ignore(streamsize __n); 00622 00623 template<> 00624 basic_istream<wchar_t>& 00625 basic_istream<wchar_t>:: 00626 ignore(streamsize __n, int_type __delim); 00627 #endif 00628 00629 /** 00630 * @brief Performs setup work for input streams. 00631 * 00632 * Objects of this class are created before all of the standard 00633 * extractors are run. It is responsible for <em>exception-safe 00634 * prefix and suffix operations,</em> although only prefix actions 00635 * are currently required by the standard. 00636 */ 00637 template<typename _CharT, typename _Traits> 00638 class basic_istream<_CharT, _Traits>::sentry 00639 { 00640 // Data Members. 00641 bool _M_ok; 00642 00643 public: 00644 /// Easy access to dependant types. 00645 typedef _Traits traits_type; 00646 typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 00647 typedef basic_istream<_CharT, _Traits> __istream_type; 00648 typedef typename __istream_type::__ctype_type __ctype_type; 00649 typedef typename _Traits::int_type __int_type; 00650 00651 /** 00652 * @brief The constructor performs all the work. 00653 * @param is The input stream to guard. 00654 * @param noskipws Whether to consume whitespace or not. 00655 * 00656 * If the stream state is good (@a is.good() is true), then the 00657 * following actions are performed, otherwise the sentry state 00658 * is false (<em>not okay</em>) and failbit is set in the 00659 * stream state. 00660 * 00661 * The sentry's preparatory actions are: 00662 * 00663 * -# if the stream is tied to an output stream, @c is.tie()->flush() 00664 * is called to synchronize the output sequence 00665 * -# if @a noskipws is false, and @c ios_base::skipws is set in 00666 * @c is.flags(), the sentry extracts and discards whitespace 00667 * characters from the stream. The currently imbued locale is 00668 * used to determine whether each character is whitespace. 00669 * 00670 * If the stream state is still good, then the sentry state becomes 00671 * true (@a okay). 00672 */ 00673 explicit 00674 sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); 00675 00676 /** 00677 * @brief Quick status checking. 00678 * @return The sentry state. 00679 * 00680 * For ease of use, sentries may be converted to booleans. The 00681 * return value is that of the sentry state (true == okay). 00682 */ 00683 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00684 explicit 00685 #endif 00686 operator bool() const 00687 { return _M_ok; } 00688 }; 00689 00690 // [27.6.1.2.3] character extraction templates 00691 //@{ 00692 /** 00693 * @brief Character extractors 00694 * @param in An input stream. 00695 * @param c A character reference. 00696 * @return in 00697 * 00698 * Behaves like one of the formatted arithmetic extractors described in 00699 * std::basic_istream. After constructing a sentry object with good 00700 * status, this function extracts a character (if one is available) and 00701 * stores it in @a c. Otherwise, sets failbit in the input stream. 00702 */ 00703 template<typename _CharT, typename _Traits> 00704 basic_istream<_CharT, _Traits>& 00705 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c); 00706 00707 template<class _Traits> 00708 inline basic_istream<char, _Traits>& 00709 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) 00710 { return (__in >> reinterpret_cast<char&>(__c)); } 00711 00712 template<class _Traits> 00713 inline basic_istream<char, _Traits>& 00714 operator>>(basic_istream<char, _Traits>& __in, signed char& __c) 00715 { return (__in >> reinterpret_cast<char&>(__c)); } 00716 //@} 00717 00718 //@{ 00719 /** 00720 * @brief Character string extractors 00721 * @param in An input stream. 00722 * @param s A pointer to a character array. 00723 * @return in 00724 * 00725 * Behaves like one of the formatted arithmetic extractors described in 00726 * std::basic_istream. After constructing a sentry object with good 00727 * status, this function extracts up to @c n characters and stores them 00728 * into the array starting at @a s. @c n is defined as: 00729 * 00730 * - if @c width() is greater than zero, @c n is width() otherwise 00731 * - @c n is <em>the number of elements of the largest array of * 00732 * - @c char_type that can store a terminating @c eos.</em> 00733 * - [27.6.1.2.3]/6 00734 * 00735 * Characters are extracted and stored until one of the following happens: 00736 * - @c n-1 characters are stored 00737 * - EOF is reached 00738 * - the next character is whitespace according to the current locale 00739 * - the next character is a null byte (i.e., @c charT() ) 00740 * 00741 * @c width(0) is then called for the input stream. 00742 * 00743 * If no characters are extracted, sets failbit. 00744 */ 00745 template<typename _CharT, typename _Traits> 00746 basic_istream<_CharT, _Traits>& 00747 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s); 00748 00749 // Explicit specialization declaration, defined in src/istream.cc. 00750 template<> 00751 basic_istream<char>& 00752 operator>>(basic_istream<char>& __in, char* __s); 00753 00754 template<class _Traits> 00755 inline basic_istream<char, _Traits>& 00756 operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s) 00757 { return (__in >> reinterpret_cast<char*>(__s)); } 00758 00759 template<class _Traits> 00760 inline basic_istream<char, _Traits>& 00761 operator>>(basic_istream<char, _Traits>& __in, signed char* __s) 00762 { return (__in >> reinterpret_cast<char*>(__s)); } 00763 //@} 00764 00765 // 27.6.1.5 Template class basic_iostream 00766 /** 00767 * @brief Merging istream and ostream capabilities. 00768 * @ingroup io 00769 * 00770 * This class multiply inherits from the input and output stream classes 00771 * simply to provide a single interface. 00772 */ 00773 template<typename _CharT, typename _Traits> 00774 class basic_iostream 00775 : public basic_istream<_CharT, _Traits>, 00776 public basic_ostream<_CharT, _Traits> 00777 { 00778 public: 00779 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00780 // 271. basic_iostream missing typedefs 00781 // Types (inherited): 00782 typedef _CharT char_type; 00783 typedef typename _Traits::int_type int_type; 00784 typedef typename _Traits::pos_type pos_type; 00785 typedef typename _Traits::off_type off_type; 00786 typedef _Traits traits_type; 00787 00788 // Non-standard Types: 00789 typedef basic_istream<_CharT, _Traits> __istream_type; 00790 typedef basic_ostream<_CharT, _Traits> __ostream_type; 00791 00792 /** 00793 * @brief Constructor does nothing. 00794 * 00795 * Both of the parent classes are initialized with the same 00796 * streambuf pointer passed to this constructor. 00797 */ 00798 explicit 00799 basic_iostream(basic_streambuf<_CharT, _Traits>* __sb) 00800 : __istream_type(__sb), __ostream_type(__sb) { } 00801 00802 /** 00803 * @brief Destructor does nothing. 00804 */ 00805 virtual 00806 ~basic_iostream() { } 00807 00808 protected: 00809 basic_iostream() 00810 : __istream_type(), __ostream_type() { } 00811 }; 00812 00813 // [27.6.1.4] standard basic_istream manipulators 00814 /** 00815 * @brief Quick and easy way to eat whitespace 00816 * 00817 * This manipulator extracts whitespace characters, stopping when the 00818 * next character is non-whitespace, or when the input sequence is empty. 00819 * If the sequence is empty, @c eofbit is set in the stream, but not 00820 * @c failbit. 00821 * 00822 * The current locale is used to distinguish whitespace characters. 00823 * 00824 * Example: 00825 * @code 00826 * MyClass mc; 00827 * 00828 * std::cin >> std::ws >> mc; 00829 * @endcode 00830 * will skip leading whitespace before calling operator>> on cin and your 00831 * object. Note that the same effect can be achieved by creating a 00832 * std::basic_istream::sentry inside your definition of operator>>. 00833 */ 00834 template<typename _CharT, typename _Traits> 00835 basic_istream<_CharT, _Traits>& 00836 ws(basic_istream<_CharT, _Traits>& __is); 00837 00838 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00839 // [27.7.1.6] Rvalue stream extraction 00840 /** 00841 * @brief Generic extractor for rvalue stream 00842 * @param is An input stream. 00843 * @param x A reference to the extraction target. 00844 * @return is 00845 * 00846 * This is just a forwarding function to allow extraction from 00847 * rvalue streams since they won't bind to the extractor functions 00848 * that take an lvalue reference. 00849 */ 00850 template<typename _CharT, typename _Traits, typename _Tp> 00851 inline basic_istream<_CharT, _Traits>& 00852 operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) 00853 { return (__is >> __x); } 00854 #endif // __GXX_EXPERIMENTAL_CXX0X__ 00855 00856 _GLIBCXX_END_NAMESPACE_VERSION 00857 } // namespace 00858 00859 #include <bits/istream.tcc> 00860 00861 #endif /* _GLIBCXX_ISTREAM */