|
All the unformatted input functions have some common behavior. Each starts by constructing a temporary object of type std::basic_istream::sentry with the second argument (noskipws) set to true. This has several effects, concluding with the setting of a status flag; see the sentry documentation for more.
If the sentry status is good, the function tries to extract whatever data is appropriate for the type of the argument.
The number of characters extracted is stored for later retrieval by gcount().
If an exception is thrown during extraction, ios_base::badbit will be turned on in the stream's error state (without causing an ios_base::failure to be thrown) and the original exception will be rethrown if badbit is set in the exceptions mask.
|
int_type | get () |
|
__istream_type & | get (char_type &__c) |
|
__istream_type & | get (char_type *__s, streamsize __n, char_type __delim) |
|
__istream_type & | get (char_type *__s, streamsize __n) |
|
__istream_type & | get (__streambuf_type &__sb, char_type __delim) |
|
__istream_type & | get (__streambuf_type &__sb) |
|
__istream_type & | getline (char_type *__s, streamsize __n, char_type __delim) |
|
__istream_type & | getline (char_type *__s, streamsize __n) |
|
__istream_type & | ignore (streamsize __n, int_type __delim) |
|
__istream_type & | ignore (streamsize __n) |
|
__istream_type & | ignore () |
|
int_type | peek () |
|
__istream_type & | read (char_type *__s, streamsize __n) |
|
streamsize | readsome (char_type *__s, streamsize __n) |
|
__istream_type & | putback (char_type __c) |
|
__istream_type & | unget () |
|
int | sync () |
|
pos_type | tellg () |
|
__istream_type & | seekg (pos_type) |
|
__istream_type & | seekg (off_type, ios_base::seekdir) |
|
| basic_istream () |
|
| basic_istream (const basic_istream &)=delete |
|
| basic_istream (basic_istream &&__rhs) |
|
basic_istream & | operator= (const basic_istream &)=delete |
|
basic_istream & | operator= (basic_istream &&__rhs) |
|
void | swap (basic_istream &__rhs) |
|
template<typename _ValueT > |
__istream_type & | _M_extract (_ValueT &__v) |
|
template<typename _CharT, typename _Traits>
class std::basic_istream< _CharT, _Traits >
Template class basic_istream.
- Template Parameters
-
_CharT | Type of character stream. |
_Traits | Traits for character type, defaults to char_traits<_CharT>. |
This is the base class for all input streams. It provides text formatting of all builtin types, and communicates with any class derived from basic_streambuf to do the actual input.
Definition at line 83 of file iosfwd.
template<typename _CharT , typename _Traits >
Extraction into another streambuf.
- Parameters
-
__sb | A streambuf in which to store data. |
__delim | A "stop" character. |
- Returns
- *this
Characters are extracted and inserted into __sb until one of the following happens:
- the input sequence reaches EOF
- insertion into the output buffer fails (in this case, the character that would have been inserted is not extracted)
- the next character equals __delim (in this case, the character is not extracted)
- an exception occurs (and in this case is caught)
If no characters are stored, failbit is set in the stream's error state.
Definition at line 364 of file istream.tcc.
template<typename _CharT , typename _Traits >
Simple multiple-character extraction.
- Parameters
-
__s | Pointer to an array. |
__n | Maximum number of characters to store in __s. |
__delim | A "stop" character. |
- Returns
- *this
Characters are extracted and stored into __s until one of the following happens:
__n-1
characters are stored
- the input sequence reaches EOF
- the next character equals __delim, in which case the character is not extracted
If no characters are stored, failbit is set in the stream's error state.
In any case, a null character is stored into the next location in the array.
- Note
- This function is not overloaded on signed char and unsigned char.
Definition at line 317 of file istream.tcc.
template<typename _CharT , typename _Traits >
String extraction.
- Parameters
-
__s | A character array in which to store the data. |
__n | Maximum number of characters to extract. |
__delim | A "stop" character. |
- Returns
- *this
Extracts and stores characters into __s until one of the following happens. Note that these criteria are required to be tested in the order listed here, to allow an input line to exactly fill the __s array without setting failbit.
- the input sequence reaches end-of-file, in which case eofbit is set in the stream error state
- the next character equals
__delim
, in which case the character is extracted (and therefore counted in gcount()
) but not stored
__n-1
characters are stored, in which case failbit is set in the stream error state
If no characters are extracted, failbit is set. (An empty line of input should therefore not cause failbit to be set.)
In any case, a null character is stored in the next location in the array.
Definition at line 408 of file istream.tcc.
template<typename _CharT , typename _Traits >
Discarding characters.
- Parameters
-
__n | Number of characters to discard. |
__delim | A "stop" character. |
- Returns
- *this
Extracts characters and throws them away until one of the following happens:
- if __n
!=
std::numeric_limits<int>::max()
, __n characters are extracted
- the input sequence reaches end-of-file
- the next character equals __delim (in this case, the character is extracted); note that this condition will never occur if __delim equals
traits::eof()
.
NB: Provide three overloads, instead of the single function (with defaults) mandated by the Standard: this leads to a better performing implementation, while still conforming to the Standard.
Definition at line 563 of file istream.tcc.
template<typename _CharT , typename _Traits >
Extracting into another streambuf.
- Parameters
-
__sb | A pointer to a streambuf |
This function behaves like one of the basic arithmetic extractors, in that it also constructs a sentry object and has the same error handling behavior.
If __sb
is NULL, the stream will set failbit in its error state.
Characters are extracted from this stream and inserted into the __sb
streambuf until one of the following occurs:
- the input stream reaches end-of-file,
- insertion into the output buffer fails (in this case, the character that would have been inserted is not extracted), or
- an exception occurs (and in this case is caught)
If the function inserts no characters, failbit is set.
Definition at line 212 of file istream.tcc.
template<typename _CharT , typename _Traits >
Looking ahead in the stream.
- Returns
- The next character, or eof().
If, after constructing the sentry object, good()
is false, returns traits::eof()
. Otherwise reads but does not extract the next input character.
Definition at line 628 of file istream.tcc.
template<typename _CharT , typename _Traits >
Unextracting a single character.
- Parameters
-
__c | The character to push back into the input stream. |
- Returns
- *this
If rdbuf()
is not null, calls rdbuf()->sputbackc(c)
.
If rdbuf()
is null or if sputbackc()
fails, sets badbit in the error state.
- Note
- This function first clears eofbit. Since no characters are extracted, the next call to
gcount()
will return 0, as required by DR 60.
Definition at line 719 of file istream.tcc.
template<typename _CharT , typename _Traits >
Extraction without delimiters.
- Parameters
-
__s | A character array. |
__n | Maximum number of characters to store. |
- Returns
- *this
If the stream state is good()
, extracts characters and stores them into __s until one of the following happens:
- __n characters are stored
- the input sequence reaches end-of-file, in which case the error state is set to
failbit|eofbit
.
- Note
- This function is not overloaded on signed char and unsigned char.
Definition at line 658 of file istream.tcc.
template<typename _CharT , typename _Traits >
Extraction until the buffer is exhausted, but no more.
- Parameters
-
__s | A character array. |
__n | Maximum number of characters to store. |
- Returns
- The number of characters extracted.
Extracts characters and stores them into __s depending on the number of characters remaining in the streambuf's buffer, rdbuf()->in_avail()
, called A
here:
- if
A
==
-1
, sets eofbit and extracts no characters
- if
A
==
0
, extracts no characters
- if
A
>
0
, extracts min(A,n)
The goal is to empty the current buffer, and to not request any more from the external input sequence controlled by the streambuf.
Definition at line 687 of file istream.tcc.
template<typename _CharT , typename _Traits >
Changing the current read position.
- Parameters
-
__off | A file offset object. |
__dir | The direction in which to seek. |
- Returns
- *this
If fail()
is not true, calls rdbuf()->pubseekoff(__off,__dir)
. If that function fails, sets failbit.
- Note
- This function first clears eofbit. It does not count the number of characters extracted, if any, and therefore does not affect the next call to
gcount()
.
Definition at line 892 of file istream.tcc.
template<typename _CharT , typename _Traits >
Changing the current read position.
- Parameters
-
__pos | A file position object. |
- Returns
- *this
If fail()
is not true, calls rdbuf()->pubseekpos(__pos)
. If that function fails, sets failbit.
- Note
- This function first clears eofbit. It does not count the number of characters extracted, if any, and therefore does not affect the next call to
gcount()
.
Definition at line 853 of file istream.tcc.
template<typename _CharT , typename _Traits >
Synchronizing the stream buffer.
- Returns
- 0 on success, -1 on failure
If rdbuf()
is a null pointer, returns -1.
Otherwise, calls rdbuf()->pubsync()
, and if that returns -1, sets badbit and returns -1.
Otherwise, returns 0.
- Note
- This function does not count the number of characters extracted, if any, and therefore does not affect the next call to
gcount()
.
Definition at line 789 of file istream.tcc.
template<typename _CharT , typename _Traits >
Getting the current read position.
- Returns
- A file position object.
If fail()
is not false, returns pos_type
(-1) to indicate failure. Otherwise returns rdbuf()->pubseekoff(0,cur,in)
.
- Note
- This function does not count the number of characters extracted, if any, and therefore does not affect the next call to
gcount()
. At variance with putback, unget and seekg, eofbit is not cleared first.
Definition at line 825 of file istream.tcc.
template<typename _CharT , typename _Traits >
Unextracting the previous character.
- Returns
- *this
If rdbuf()
is not null, calls rdbuf()->sungetc(c)
.
If rdbuf()
is null or if sungetc()
fails, sets badbit in the error state.
- Note
- This function first clears eofbit. Since no characters are extracted, the next call to
gcount()
will return 0, as required by DR 60.
Definition at line 754 of file istream.tcc.
Referenced by std::__detail::operator>>().