public member function
<istream>
Decrement get pointer
Decrements the internal
get pointer by one, making the last character extracted from the input sequence available again as the next character to be read from the stream.
The function effectively calls the
sungetc member function of the
streambuf object associated to the stream.
A subsequent call to member
gcount will return zero.
Parameters
none
Return Value
The function returns
*this.
Errors are signaled by modifying the internal state flags:
| flag | error |
| eofbit | - |
| failbit | The stream was at the end of the source of characters before the function was called. |
| badbit | An error other than the above happened. |
Additionally, in any of these cases, if the appropriate flag has been set with member function
ios::exceptions, an exception of type
ios_base::failure is thrown.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
// istream::unget example
#include <iostream>
using namespace std;
int main () {
char c;
int n;
char str[256];
cout << "Enter a number or a word: ";
c = cin.get();
if ( (c >= '0') && (c <= '9') )
{
cin.unget();
cin >> n;
cout << "You have entered number " << n << endl;
}
else
{
cin.unget();
cin >> str;
cout << " You have entered word " << str << endl;
}
return 0;
}
|
Basic template member declaration
(basic_istream<charT,traits>)
|
basic_istream& unget ( );
|
See also
- istream::get
- Get unformatted data from stream (public member function)
- istream::putback
- Put character back (public member function)