libstdc++
istream
Go to the documentation of this file.
1 // Input streams -*- C++ -*-
2 
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009, 2010, 2011
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
21 
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
26 
27 //
28 // ISO C++ 14882: 27.6.1 Input streams
29 //
30 
31 /** @file include/istream
32  * This is a Standard C++ Library header.
33  */
34 
35 #ifndef _GLIBCXX_ISTREAM
36 #define _GLIBCXX_ISTREAM 1
37 
38 #pragma GCC system_header
39 
40 #include <ios>
41 #include <ostream>
42 
43 namespace std _GLIBCXX_VISIBILITY(default)
44 {
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
46 
47  /**
48  * @brief Template class basic_istream.
49  * @ingroup io
50  *
51  * This is the base class for all input streams. It provides text
52  * formatting of all builtin types, and communicates with any class
53  * derived from basic_streambuf to do the actual input.
54  */
55  template<typename _CharT, typename _Traits>
56  class basic_istream : virtual public basic_ios<_CharT, _Traits>
57  {
58  public:
59  // Types (inherited from basic_ios (27.4.4)):
60  typedef _CharT char_type;
61  typedef typename _Traits::int_type int_type;
62  typedef typename _Traits::pos_type pos_type;
63  typedef typename _Traits::off_type off_type;
64  typedef _Traits traits_type;
65 
66  // Non-standard Types:
67  typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
68  typedef basic_ios<_CharT, _Traits> __ios_type;
69  typedef basic_istream<_CharT, _Traits> __istream_type;
70  typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
71  __num_get_type;
72  typedef ctype<_CharT> __ctype_type;
73 
74  protected:
75  // Data Members:
76  /**
77  * The number of characters extracted in the previous unformatted
78  * function; see gcount().
79  */
81 
82  public:
83  /**
84  * @brief Base constructor.
85  *
86  * This ctor is almost never called by the user directly, rather from
87  * derived classes' initialization lists, which pass a pointer to
88  * their own stream buffer.
89  */
90  explicit
92  : _M_gcount(streamsize(0))
93  { this->init(__sb); }
94 
95  /**
96  * @brief Base destructor.
97  *
98  * This does very little apart from providing a virtual base dtor.
99  */
100  virtual
102  { _M_gcount = streamsize(0); }
103 
104  /// Safe prefix/suffix operations.
105  class sentry;
106  friend class sentry;
107 
108  //@{
109  /**
110  * @brief Interface for manipulators.
111  *
112  * Manipulators such as @c std::ws and @c std::dec use these
113  * functions in constructs like
114  * <code>std::cin >> std::ws</code>.
115  * For more information, see the iomanip header.
116  */
117  __istream_type&
119  { return __pf(*this); }
120 
121  __istream_type&
123  {
124  __pf(*this);
125  return *this;
126  }
127 
128  __istream_type&
130  {
131  __pf(*this);
132  return *this;
133  }
134  //@}
135 
136  //@{
137  /**
138  * @name Extractors
139  *
140  * All the @c operator>> functions (aka <em>formatted input
141  * functions</em>) have some common behavior. Each starts by
142  * constructing a temporary object of type std::basic_istream::sentry
143  * with the second argument (noskipws) set to false. This has several
144  * effects, concluding with the setting of a status flag; see the
145  * sentry documentation for more.
146  *
147  * If the sentry status is good, the function tries to extract
148  * whatever data is appropriate for the type of the argument.
149  *
150  * If an exception is thrown during extraction, ios_base::badbit
151  * will be turned on in the stream's error state without causing an
152  * ios_base::failure to be thrown. The original exception will then
153  * be rethrown.
154  */
155 
156  //@{
157  /**
158  * @brief Integer arithmetic extractors
159  * @param __n A variable of builtin integral type.
160  * @return @c *this if successful
161  *
162  * These functions use the stream's current locale (specifically, the
163  * @c num_get facet) to parse the input data.
164  */
165  __istream_type&
166  operator>>(bool& __n)
167  { return _M_extract(__n); }
168 
169  __istream_type&
170  operator>>(short& __n);
171 
172  __istream_type&
173  operator>>(unsigned short& __n)
174  { return _M_extract(__n); }
175 
176  __istream_type&
177  operator>>(int& __n);
178 
179  __istream_type&
180  operator>>(unsigned int& __n)
181  { return _M_extract(__n); }
182 
183  __istream_type&
184  operator>>(long& __n)
185  { return _M_extract(__n); }
186 
187  __istream_type&
188  operator>>(unsigned long& __n)
189  { return _M_extract(__n); }
190 
191 #ifdef _GLIBCXX_USE_LONG_LONG
192  __istream_type&
193  operator>>(long long& __n)
194  { return _M_extract(__n); }
195 
196  __istream_type&
197  operator>>(unsigned long long& __n)
198  { return _M_extract(__n); }
199 #endif
200  //@}
201 
202  //@{
203  /**
204  * @brief Floating point arithmetic extractors
205  * @param __f A variable of builtin floating point type.
206  * @return @c *this if successful
207  *
208  * These functions use the stream's current locale (specifically, the
209  * @c num_get facet) to parse the input data.
210  */
211  __istream_type&
212  operator>>(float& __f)
213  { return _M_extract(__f); }
214 
215  __istream_type&
216  operator>>(double& __f)
217  { return _M_extract(__f); }
218 
219  __istream_type&
220  operator>>(long double& __f)
221  { return _M_extract(__f); }
222  //@}
223 
224  /**
225  * @brief Basic arithmetic extractors
226  * @param __p A variable of pointer type.
227  * @return @c *this if successful
228  *
229  * These functions use the stream's current locale (specifically, the
230  * @c num_get facet) to parse the input data.
231  */
232  __istream_type&
233  operator>>(void*& __p)
234  { return _M_extract(__p); }
235 
236  /**
237  * @brief Extracting into another streambuf.
238  * @param __sb A pointer to a streambuf
239  *
240  * This function behaves like one of the basic arithmetic extractors,
241  * in that it also constructs a sentry object and has the same error
242  * handling behavior.
243  *
244  * If @p __sb is NULL, the stream will set failbit in its error state.
245  *
246  * Characters are extracted from this stream and inserted into the
247  * @p __sb streambuf until one of the following occurs:
248  *
249  * - the input stream reaches end-of-file,
250  * - insertion into the output buffer fails (in this case, the
251  * character that would have been inserted is not extracted), or
252  * - an exception occurs (and in this case is caught)
253  *
254  * If the function inserts no characters, failbit is set.
255  */
256  __istream_type&
257  operator>>(__streambuf_type* __sb);
258  //@}
259 
260  // [27.6.1.3] unformatted input
261  /**
262  * @brief Character counting
263  * @return The number of characters extracted by the previous
264  * unformatted input function dispatched for this stream.
265  */
266  streamsize
267  gcount() const
268  { return _M_gcount; }
269 
270  //@{
271  /**
272  * @name Unformatted Input Functions
273  *
274  * All the unformatted input functions have some common behavior.
275  * Each starts by constructing a temporary object of type
276  * std::basic_istream::sentry with the second argument (noskipws)
277  * set to true. This has several effects, concluding with the
278  * setting of a status flag; see the sentry documentation for more.
279  *
280  * If the sentry status is good, the function tries to extract
281  * whatever data is appropriate for the type of the argument.
282  *
283  * The number of characters extracted is stored for later retrieval
284  * by gcount().
285  *
286  * If an exception is thrown during extraction, ios_base::badbit
287  * will be turned on in the stream's error state without causing an
288  * ios_base::failure to be thrown. The original exception will then
289  * be rethrown.
290  */
291 
292  /**
293  * @brief Simple extraction.
294  * @return A character, or eof().
295  *
296  * Tries to extract a character. If none are available, sets failbit
297  * and returns traits::eof().
298  */
299  int_type
300  get();
301 
302  /**
303  * @brief Simple extraction.
304  * @param __c The character in which to store data.
305  * @return *this
306  *
307  * Tries to extract a character and store it in @a __c. If none are
308  * available, sets failbit and returns traits::eof().
309  *
310  * @note This function is not overloaded on signed char and
311  * unsigned char.
312  */
313  __istream_type&
314  get(char_type& __c);
315 
316  /**
317  * @brief Simple multiple-character extraction.
318  * @param __s Pointer to an array.
319  * @param __n Maximum number of characters to store in @a __s.
320  * @param __delim A "stop" character.
321  * @return *this
322  *
323  * Characters are extracted and stored into @a __s until one of the
324  * following happens:
325  *
326  * - @c __n-1 characters are stored
327  * - the input sequence reaches EOF
328  * - the next character equals @a __delim, in which case the character
329  * is not extracted
330  *
331  * If no characters are stored, failbit is set in the stream's error
332  * state.
333  *
334  * In any case, a null character is stored into the next location in
335  * the array.
336  *
337  * @note This function is not overloaded on signed char and
338  * unsigned char.
339  */
340  __istream_type&
341  get(char_type* __s, streamsize __n, char_type __delim);
342 
343  /**
344  * @brief Simple multiple-character extraction.
345  * @param __s Pointer to an array.
346  * @param __n Maximum number of characters to store in @a s.
347  * @return *this
348  *
349  * Returns @c get(__s,__n,widen(&apos;\\n&apos;)).
350  */
351  __istream_type&
352  get(char_type* __s, streamsize __n)
353  { return this->get(__s, __n, this->widen('\n')); }
354 
355  /**
356  * @brief Extraction into another streambuf.
357  * @param __sb A streambuf in which to store data.
358  * @param __delim A "stop" character.
359  * @return *this
360  *
361  * Characters are extracted and inserted into @a __sb until one of the
362  * following happens:
363  *
364  * - the input sequence reaches EOF
365  * - insertion into the output buffer fails (in this case, the
366  * character that would have been inserted is not extracted)
367  * - the next character equals @a __delim (in this case, the character
368  * is not extracted)
369  * - an exception occurs (and in this case is caught)
370  *
371  * If no characters are stored, failbit is set in the stream's error
372  * state.
373  */
374  __istream_type&
375  get(__streambuf_type& __sb, char_type __delim);
376 
377  /**
378  * @brief Extraction into another streambuf.
379  * @param __sb A streambuf in which to store data.
380  * @return *this
381  *
382  * Returns @c get(__sb,widen(&apos;\\n&apos;)).
383  */
384  __istream_type&
385  get(__streambuf_type& __sb)
386  { return this->get(__sb, this->widen('\n')); }
387 
388  /**
389  * @brief String extraction.
390  * @param __s A character array in which to store the data.
391  * @param __n Maximum number of characters to extract.
392  * @param __delim A "stop" character.
393  * @return *this
394  *
395  * Extracts and stores characters into @a __s until one of the
396  * following happens. Note that these criteria are required to be
397  * tested in the order listed here, to allow an input line to exactly
398  * fill the @a __s array without setting failbit.
399  *
400  * -# the input sequence reaches end-of-file, in which case eofbit
401  * is set in the stream error state
402  * -# the next character equals @c __delim, in which case the character
403  * is extracted (and therefore counted in @c gcount()) but not stored
404  * -# @c __n-1 characters are stored, in which case failbit is set
405  * in the stream error state
406  *
407  * If no characters are extracted, failbit is set. (An empty line of
408  * input should therefore not cause failbit to be set.)
409  *
410  * In any case, a null character is stored in the next location in
411  * the array.
412  */
413  __istream_type&
414  getline(char_type* __s, streamsize __n, char_type __delim);
415 
416  /**
417  * @brief String extraction.
418  * @param __s A character array in which to store the data.
419  * @param __n Maximum number of characters to extract.
420  * @return *this
421  *
422  * Returns @c getline(__s,__n,widen(&apos;\\n&apos;)).
423  */
424  __istream_type&
426  { return this->getline(__s, __n, this->widen('\n')); }
427 
428  /**
429  * @brief Discarding characters
430  * @param __n Number of characters to discard.
431  * @param __delim A "stop" character.
432  * @return *this
433  *
434  * Extracts characters and throws them away until one of the
435  * following happens:
436  * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
437  * characters are extracted
438  * - the input sequence reaches end-of-file
439  * - the next character equals @a __delim (in this case, the character
440  * is extracted); note that this condition will never occur if
441  * @a __delim equals @c traits::eof().
442  *
443  * NB: Provide three overloads, instead of the single function
444  * (with defaults) mandated by the Standard: this leads to a
445  * better performing implementation, while still conforming to
446  * the Standard.
447  */
448  __istream_type&
449  ignore(streamsize __n, int_type __delim);
450 
451  __istream_type&
452  ignore(streamsize __n);
453 
454  __istream_type&
455  ignore();
456 
457  /**
458  * @brief Looking ahead in the stream
459  * @return The next character, or eof().
460  *
461  * If, after constructing the sentry object, @c good() is false,
462  * returns @c traits::eof(). Otherwise reads but does not extract
463  * the next input character.
464  */
465  int_type
466  peek();
467 
468  /**
469  * @brief Extraction without delimiters.
470  * @param __s A character array.
471  * @param __n Maximum number of characters to store.
472  * @return *this
473  *
474  * If the stream state is @c good(), extracts characters and stores
475  * them into @a __s until one of the following happens:
476  * - @a __n characters are stored
477  * - the input sequence reaches end-of-file, in which case the error
478  * state is set to @c failbit|eofbit.
479  *
480  * @note This function is not overloaded on signed char and
481  * unsigned char.
482  */
483  __istream_type&
484  read(char_type* __s, streamsize __n);
485 
486  /**
487  * @brief Extraction until the buffer is exhausted, but no more.
488  * @param __s A character array.
489  * @param __n Maximum number of characters to store.
490  * @return The number of characters extracted.
491  *
492  * Extracts characters and stores them into @a __s depending on the
493  * number of characters remaining in the streambuf's buffer,
494  * @c rdbuf()->in_avail(), called @c A here:
495  * - if @c A @c == @c -1, sets eofbit and extracts no characters
496  * - if @c A @c == @c 0, extracts no characters
497  * - if @c A @c > @c 0, extracts @c min(A,n)
498  *
499  * The goal is to empty the current buffer, and to not request any
500  * more from the external input sequence controlled by the streambuf.
501  */
502  streamsize
503  readsome(char_type* __s, streamsize __n);
504 
505  /**
506  * @brief Unextracting a single character.
507  * @param __c The character to push back into the input stream.
508  * @return *this
509  *
510  * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
511  *
512  * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
513  * the error state.
514  *
515  * @note This function first clears eofbit. Since no characters
516  * are extracted, the next call to @c gcount() will return 0,
517  * as required by DR 60.
518  */
519  __istream_type&
520  putback(char_type __c);
521 
522  /**
523  * @brief Unextracting the previous character.
524  * @return *this
525  *
526  * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
527  *
528  * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
529  * the error state.
530  *
531  * @note This function first clears eofbit. Since no characters
532  * are extracted, the next call to @c gcount() will return 0,
533  * as required by DR 60.
534  */
535  __istream_type&
536  unget();
537 
538  /**
539  * @brief Synchronizing the stream buffer.
540  * @return 0 on success, -1 on failure
541  *
542  * If @c rdbuf() is a null pointer, returns -1.
543  *
544  * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
545  * sets badbit and returns -1.
546  *
547  * Otherwise, returns 0.
548  *
549  * @note This function does not count the number of characters
550  * extracted, if any, and therefore does not affect the next
551  * call to @c gcount().
552  */
553  int
554  sync();
555 
556  /**
557  * @brief Getting the current read position.
558  * @return A file position object.
559  *
560  * If @c fail() is not false, returns @c pos_type(-1) to indicate
561  * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
562  *
563  * @note This function does not count the number of characters
564  * extracted, if any, and therefore does not affect the next
565  * call to @c gcount(). At variance with putback, unget and
566  * seekg, eofbit is not cleared first.
567  */
568  pos_type
569  tellg();
570 
571  /**
572  * @brief Changing the current read position.
573  * @param __pos A file position object.
574  * @return *this
575  *
576  * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If
577  * that function fails, sets failbit.
578  *
579  * @note This function first clears eofbit. It does not count the
580  * number of characters extracted, if any, and therefore does
581  * not affect the next call to @c gcount().
582  */
583  __istream_type&
584  seekg(pos_type);
585 
586  /**
587  * @brief Changing the current read position.
588  * @param __off A file offset object.
589  * @param __dir The direction in which to seek.
590  * @return *this
591  *
592  * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
593  * If that function fails, sets failbit.
594  *
595  * @note This function first clears eofbit. It does not count the
596  * number of characters extracted, if any, and therefore does
597  * not affect the next call to @c gcount().
598  */
599  __istream_type&
600  seekg(off_type, ios_base::seekdir);
601  //@}
602 
603  protected:
604  basic_istream()
605  : _M_gcount(streamsize(0))
606  { this->init(0); }
607 
608  template<typename _ValueT>
609  __istream_type&
610  _M_extract(_ValueT& __v);
611  };
612 
613  /// Explicit specialization declarations, defined in src/istream.cc.
614  template<>
615  basic_istream<char>&
617  getline(char_type* __s, streamsize __n, char_type __delim);
618 
619  template<>
620  basic_istream<char>&
622  ignore(streamsize __n);
623 
624  template<>
625  basic_istream<char>&
627  ignore(streamsize __n, int_type __delim);
628 
629 #ifdef _GLIBCXX_USE_WCHAR_T
630  template<>
631  basic_istream<wchar_t>&
633  getline(char_type* __s, streamsize __n, char_type __delim);
634 
635  template<>
636  basic_istream<wchar_t>&
638  ignore(streamsize __n);
639 
640  template<>
641  basic_istream<wchar_t>&
643  ignore(streamsize __n, int_type __delim);
644 #endif
645 
646  /**
647  * @brief Performs setup work for input streams.
648  *
649  * Objects of this class are created before all of the standard
650  * extractors are run. It is responsible for <em>exception-safe
651  * prefix and suffix operations,</em> although only prefix actions
652  * are currently required by the standard.
653  */
654  template<typename _CharT, typename _Traits>
655  class basic_istream<_CharT, _Traits>::sentry
656  {
657  // Data Members.
658  bool _M_ok;
659 
660  public:
661  /// Easy access to dependant types.
662  typedef _Traits traits_type;
666  typedef typename _Traits::int_type __int_type;
667 
668  /**
669  * @brief The constructor performs all the work.
670  * @param __is The input stream to guard.
671  * @param __noskipws Whether to consume whitespace or not.
672  *
673  * If the stream state is good (@a __is.good() is true), then the
674  * following actions are performed, otherwise the sentry state
675  * is false (<em>not okay</em>) and failbit is set in the
676  * stream state.
677  *
678  * The sentry's preparatory actions are:
679  *
680  * -# if the stream is tied to an output stream, @c is.tie()->flush()
681  * is called to synchronize the output sequence
682  * -# if @a __noskipws is false, and @c ios_base::skipws is set in
683  * @c is.flags(), the sentry extracts and discards whitespace
684  * characters from the stream. The currently imbued locale is
685  * used to determine whether each character is whitespace.
686  *
687  * If the stream state is still good, then the sentry state becomes
688  * true (@a okay).
689  */
690  explicit
691  sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
692 
693  /**
694  * @brief Quick status checking.
695  * @return The sentry state.
696  *
697  * For ease of use, sentries may be converted to booleans. The
698  * return value is that of the sentry state (true == okay).
699  */
700 #ifdef __GXX_EXPERIMENTAL_CXX0X__
701  explicit
702 #endif
703  operator bool() const
704  { return _M_ok; }
705  };
706 
707  //@{
708  /**
709  * @brief Character extractors
710  * @param __in An input stream.
711  * @param __c A character reference.
712  * @return in
713  *
714  * Behaves like one of the formatted arithmetic extractors described in
715  * std::basic_istream. After constructing a sentry object with good
716  * status, this function extracts a character (if one is available) and
717  * stores it in @a __c. Otherwise, sets failbit in the input stream.
718  */
719  template<typename _CharT, typename _Traits>
721  operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
722 
723  template<class _Traits>
725  operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
726  { return (__in >> reinterpret_cast<char&>(__c)); }
727 
728  template<class _Traits>
729  inline basic_istream<char, _Traits>&
730  operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
731  { return (__in >> reinterpret_cast<char&>(__c)); }
732  //@}
733 
734  //@{
735  /**
736  * @brief Character string extractors
737  * @param __in An input stream.
738  * @param __s A pointer to a character array.
739  * @return __in
740  *
741  * Behaves like one of the formatted arithmetic extractors described in
742  * std::basic_istream. After constructing a sentry object with good
743  * status, this function extracts up to @c n characters and stores them
744  * into the array starting at @a __s. @c n is defined as:
745  *
746  * - if @c width() is greater than zero, @c n is width() otherwise
747  * - @c n is <em>the number of elements of the largest array of *
748  * - @c char_type that can store a terminating @c eos.</em>
749  * - [27.6.1.2.3]/6
750  *
751  * Characters are extracted and stored until one of the following happens:
752  * - @c n-1 characters are stored
753  * - EOF is reached
754  * - the next character is whitespace according to the current locale
755  * - the next character is a null byte (i.e., @c charT() )
756  *
757  * @c width(0) is then called for the input stream.
758  *
759  * If no characters are extracted, sets failbit.
760  */
761  template<typename _CharT, typename _Traits>
762  basic_istream<_CharT, _Traits>&
763  operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
764 
765  // Explicit specialization declaration, defined in src/istream.cc.
766  template<>
767  basic_istream<char>&
768  operator>>(basic_istream<char>& __in, char* __s);
769 
770  template<class _Traits>
771  inline basic_istream<char, _Traits>&
772  operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
773  { return (__in >> reinterpret_cast<char*>(__s)); }
774 
775  template<class _Traits>
776  inline basic_istream<char, _Traits>&
777  operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
778  { return (__in >> reinterpret_cast<char*>(__s)); }
779  //@}
780 
781  /**
782  * @brief Template class basic_iostream
783  * @ingroup io
784  *
785  * This class multiply inherits from the input and output stream classes
786  * simply to provide a single interface.
787  */
788  template<typename _CharT, typename _Traits>
789  class basic_iostream
790  : public basic_istream<_CharT, _Traits>,
791  public basic_ostream<_CharT, _Traits>
792  {
793  public:
794  // _GLIBCXX_RESOLVE_LIB_DEFECTS
795  // 271. basic_iostream missing typedefs
796  // Types (inherited):
797  typedef _CharT char_type;
798  typedef typename _Traits::int_type int_type;
799  typedef typename _Traits::pos_type pos_type;
800  typedef typename _Traits::off_type off_type;
801  typedef _Traits traits_type;
802 
803  // Non-standard Types:
804  typedef basic_istream<_CharT, _Traits> __istream_type;
805  typedef basic_ostream<_CharT, _Traits> __ostream_type;
806 
807  /**
808  * @brief Constructor does nothing.
809  *
810  * Both of the parent classes are initialized with the same
811  * streambuf pointer passed to this constructor.
812  */
813  explicit
815  : __istream_type(__sb), __ostream_type(__sb) { }
816 
817  /**
818  * @brief Destructor does nothing.
819  */
820  virtual
822 
823  protected:
825  : __istream_type(), __ostream_type() { }
826  };
827 
828  /**
829  * @brief Quick and easy way to eat whitespace
830  *
831  * This manipulator extracts whitespace characters, stopping when the
832  * next character is non-whitespace, or when the input sequence is empty.
833  * If the sequence is empty, @c eofbit is set in the stream, but not
834  * @c failbit.
835  *
836  * The current locale is used to distinguish whitespace characters.
837  *
838  * Example:
839  * @code
840  * MyClass mc;
841  *
842  * std::cin >> std::ws >> mc;
843  * @endcode
844  * will skip leading whitespace before calling operator>> on cin and your
845  * object. Note that the same effect can be achieved by creating a
846  * std::basic_istream::sentry inside your definition of operator>>.
847  */
848  template<typename _CharT, typename _Traits>
849  basic_istream<_CharT, _Traits>&
850  ws(basic_istream<_CharT, _Traits>& __is);
851 
852 #ifdef __GXX_EXPERIMENTAL_CXX0X__
853  // [27.7.1.6] Rvalue stream extraction
854  /**
855  * @brief Generic extractor for rvalue stream
856  * @param __is An input stream.
857  * @param __x A reference to the extraction target.
858  * @return is
859  *
860  * This is just a forwarding function to allow extraction from
861  * rvalue streams since they won't bind to the extractor functions
862  * that take an lvalue reference.
863  */
864  template<typename _CharT, typename _Traits, typename _Tp>
865  inline basic_istream<_CharT, _Traits>&
867  { return (__is >> __x); }
868 #endif // __GXX_EXPERIMENTAL_CXX0X__
869 
870 _GLIBCXX_END_NAMESPACE_VERSION
871 } // namespace
872 
873 #include <bits/istream.tcc>
874 
875 #endif /* _GLIBCXX_ISTREAM */
pos_type tellg()
Getting the current read position.
Definition: istream.tcc:819
__istream_type & getline(char_type *__s, streamsize __n, char_type __delim)
String extraction.
Definition: istream.tcc:402
Performs setup work for input streams.
Definition: istream:655
__istream_type & operator>>(long double &__f)
Floating point arithmetic extractors.
Definition: istream:220
Primary class template ctype facet.This template class defines classification and conversion function...
basic_istream(__streambuf_type *__sb)
Base constructor.
Definition: istream:91
virtual ~basic_iostream()
Destructor does nothing.
Definition: istream:821
char_type widen(char __c) const
Widens characters.
Definition: basic_ios.h:441
__istream_type & operator>>(unsigned long &__n)
Integer arithmetic extractors.
Definition: istream:188
_Traits traits_type
Easy access to dependant types.
Definition: istream:662
__istream_type & ignore()
Simple extraction.
Definition: istream.tcc:462
__istream_type & unget()
Unextracting the previous character.
Definition: istream.tcc:748
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
Definition: basic_ios.tcc:127
__istream_type & putback(char_type __c)
Unextracting a single character.
Definition: istream.tcc:713
__istream_type & operator>>(unsigned short &__n)
Integer arithmetic extractors.
Definition: istream:173
__istream_type & operator>>(__ios_type &(*__pf)(__ios_type &))
Interface for manipulators.
Definition: istream:122
__istream_type & operator>>(long &__n)
Integer arithmetic extractors.
Definition: istream:184
__istream_type & operator>>(__istream_type &(*__pf)(__istream_type &))
Interface for manipulators.
Definition: istream:118
__istream_type & operator>>(double &__f)
Floating point arithmetic extractors.
Definition: istream:216
streamsize gcount() const
Character counting.
Definition: istream:267
__istream_type & read(char_type *__s, streamsize __n)
Extraction without delimiters.
Definition: istream.tcc:652
int sync()
Synchronizing the stream buffer.
Definition: istream.tcc:783
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
Definition: postypes.h:100
basic_istream< _CharT, _Traits > & ws(basic_istream< _CharT, _Traits > &__is)
Quick and easy way to eat whitespace.
Definition: istream.tcc:1018
streamsize _M_gcount
Definition: istream:80
basic_iostream(basic_streambuf< _CharT, _Traits > *__sb)
Constructor does nothing.
Definition: istream:814
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
Definition: ios_base.h:201
bitset< _Nb > operator>>(size_t __position) const _GLIBCXX_NOEXCEPT
Self-explanatory.
Definition: bitset:1345
__istream_type & operator>>(unsigned long long &__n)
Integer arithmetic extractors.
Definition: istream:197
__istream_type & getline(char_type *__s, streamsize __n)
String extraction.
Definition: istream:425
__istream_type & operator>>(unsigned int &__n)
Integer arithmetic extractors.
Definition: istream:180
__istream_type & operator>>(bool &__n)
Integer arithmetic extractors.
Definition: istream:166
streamsize readsome(char_type *__s, streamsize __n)
Extraction until the buffer is exhausted, but no more.
Definition: istream.tcc:681
__istream_type & operator>>(float &__f)
Floating point arithmetic extractors.
Definition: istream:212
__istream_type & seekg(pos_type)
Changing the current read position.
Definition: istream.tcc:847
int_type peek()
Looking ahead in the stream.
Definition: istream.tcc:622
__istream_type & operator>>(void *&__p)
Basic arithmetic extractors.
Definition: istream:233
virtual ~basic_istream()
Base destructor.
Definition: istream:101
__istream_type & operator>>(long long &__n)
Integer arithmetic extractors.
Definition: istream:193
__istream_type & operator>>(ios_base &(*__pf)(ios_base &))
Interface for manipulators.
Definition: istream:129
Template class basic_iostreamThis class multiply inherits from the input and output stream classes si...
Definition: iosfwd:91