1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| // sputbackc example #include <iostream> // std::cin, std::cout, std::streambuf, std::streamsize #include <cstdio> // EOF 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 != EOF ); return 0; }
|