int_type sputbackc (char_type c);
1
2
3
4
5
6
int_type sputbackc(char_type c) {
if ( (!gptr()) || (gptr()==eback()) || (!traits_type::eq(c,gptr()[-1])) )
return pbackfail (traits_type::to_int_type(c));
gbump(-1);
return traits_type::to_int_type(*gptr());
}
traits_type::eof() ) on failure.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// sputbackc example
#include <iostream> // std::cin, std::cout, std::streambuf, std::streamsize
int main () {
char ch;
std::streambuf * pbuf = std::cin.rdbuf();
std::cout << "Please, enter some letters and then a number: ";
do {
ch = pbuf->sbumpc();
if ( (ch>='0') && (ch <='9') )
{
pbuf->sputbackc (ch);
long n;
std::cin >> n;
std::cout << "You entered number " << n << '\n';
break;
}
} while ( ch != std::streambuf::traits_type::eof() );
return 0;
}
>>.