streambuf::sungetc
int sungetc ( ); | streambuf |
cplusplus.com |
Decrease get pointer.
Moves get pointer one character back, making the last character got once again available.
Parameters.
Return Value.
The value of the character in the new get pointer position.
If the get pointer is at the beginning of the input sequence the
default behavior is to return EOF (depends on virtual private member
pbackfail).
Example.
// sungetc
#include <iostream>
using namespace std;
int main () {
char ch;
long n;
streambuf * pbuf;
pbuf = cin.rdbuf();
cout << "Please enter some letters and after a number: ";
do {
ch=pbuf->sbumpc();
if ( (ch>='0') && (ch <='9') )
{
pbuf->sungetc ();
cin >> n;
cout << "You entered number " << n << endl;
break;
}
} while (ch != EOF);
return 0;
}
This example gets characters form standard input one by one. When the first
numeric digit is found, sungetc is called to restore the position in the
stream to that digit in order to be extracted as part of a number using standard
operator >>.
Basic template member declaration ( basic_streambuf<charT,traits> ):
typedef traits::int_type int_type; int_type sungetc ( ); |
See also.
sungetc,
sgetc,
snextc,
sbumpc,
sputc
streambuf class