istream::peek
int peek ( ); | istream |
cplusplus.com |
Peek next character.
Reads and returns the next character without extracting it from the stream.
Returns EOF if stream is at the end of file and in any case where member
good() (ios::good)
would return false
Parameters.
Return Value.
The value of the next character in stream or EOF.
Example.
// istream peek
#include <iostream>
using namespace std;
int main () {
char c;
int n;
char str[256];
cout << "Enter a number or a word: ";
c=cin.peek();
if ( (c >= '0') && (c <= '9') )
{
cin >> n;
cout << "You have entered number " << n << endl;
}
else
{
cin >> str;
cout << " You have entered word " << str << endl;
}
return 0;
}
Basic template member declaration ( basic_istream<charT,traits> ):
typedef traits::int_type int_type; int_type peek ( ); |
See also.
get,
operator>>
istream class