Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
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.


Puts the most recently read character back into the stream.

basic_istream& unget( );

The stream (*this).

The unformatted input function puts back the previous element in the stream, if possible, as if by calling rdbuf ->sungetc. If rdbuf is a null pointer, or if the call to sungetc returns traits_type::eof, the function calls setstate(badbit). In any case, it returns *this.

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

int main( ) 
   char c[10], c2;
   cout << "Type 'abc': ";
   c2 = cin.get( );
   cin.unget( );
   cin.getline( &c[0], 9 );
   cout << c << endl;



Sample Output

Type 'abc': abc

Header: <istream>

Community Additions

© 2015 Microsoft