istream::putback
istream& putback (char c ); | istream |
cplusplus.com |
Put the last character back to stream.
Decrements the next-character pointer for the input buffer if c
was the last character got from the stream.
Parameters.
Return Value.
The function returns *this
Example.
// istream putback
#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.putback (c);
cin >> n;
cout << "You have entered number " << n << endl;
}
else
{
cin.putback (c);
cin >> str;
cout << " You have entered word " << str << endl;
}
return 0;
}
Basic template member declaration ( basic_istream<charT,traits> ):
typedef charT char_type; basic_istream& putback ( char_type c ); |
See also.
get,
unget,
istream class