Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Reads one or more characters from the input stream.

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



The number of characters to read from strbuf.


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


A string in which to write.


A buffer in which to write.

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

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.

// 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;





Header: <istream>

© 2015 Microsoft