Freigeben über


basic_istream::get

Reads one or more characters from the input stream.

int_type get();
basic_istream<Elem, Tr>& get(
    Elem& _Ch
);
basic_istream<Elem, Tr>& get(
        Elem *_Str,
       streamsize _Count
);
basic_istream<Elem, Tr>& get(
        Elem *_Str,
        streamsize _Count,
        Elem _Delim
);
basic_istream<Elem, Tr>& get(
        basic_streambuf<Elem, Tr>& _Strbuf
);
basic_istream<Elem, Tr>& get(
        basic_streambuf<Elem, Tr>& _Strbuf,
        Elem _Delim
);

Parameters

  • _Count
    The number of characters to read from strbuf.

  • _Delim
    The character that should terminate the read if it is encountered before _Count.

  • _Str
    A string in which to write.

  • _Ch
    A character to get.

  • _Strbuf
    A buffer in which to write.

Return Value

The parameterless form of get returns the element read as an integer or end of file. The remaining forms return the stream (*this).

Remarks

The first of these unformatted input functions extracts an element, if possible, as if by returning rdbuf->sbumpc. Otherwise, it returns traits_type::eof. If the function extracts no element, it calls setstate(failbit).

The second function extracts the int_type element meta the same way. If meta compares equal to traits_type::eof, the function calls setstate(failbit). Otherwise, it stores traits_type::to_char_type(meta) in _Ch. The function returns *this.

The third function returns get(_Str, _Count, widen('\n')).

The fourth function extracts up to _Count - 1 elements and stores them in the array beginning at _Str. It always stores char_type after any extracted elements it stores. In order of testing, extraction stops:

  • At end of file.

  • After the function extracts an element that compares equal to _Delim, in which case the element is put back to the controlled sequence.

  • After the function extracts _Count - 1 elements.

If the function extracts no elements, it calls setstate(failbit). In any case, it returns *this.

The fifth function returns get(strbuf, widen('\n')).

The sixth function extracts elements and inserts them in strbuf. Extraction stops on end-of-file or on an element that compares equal to _Delim, which is not extracted. It also stops, without extracting the element in question, if an insertion fails or throws an exception (which is caught but not rethrown). If the function extracts no elements, it calls setstate(failbit). In any case, the function returns *this.

Example

// basic_istream_get.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

int main( ) 
{
   char c[10];

   c[0] = cin.get( );
   cin.get( c[1] );
   cin.get( &c[2],3 );
   cin.get( &c[4], 4, '7' );

   cout << c << endl;
}
11
11

Requirements

Header: <istream>

Namespace: std

See Also

Concepts

basic_istream Class

basic_istream Members

iostream Programming

iostreams Conventions