Export (0) Print
Expand All
2 out of 7 rated this helpful - Rate this topic

basic_istream::get 

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

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.

_Strbuf

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

Input

11

Output

11

Header: <istream>

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.