From cppreference.com
int_typepeek();Behaves as
. After constructing and testing the sentry object, reads the next character from the input stream without extracting it.
Parameters
(none)
Return value
If good()==true, returns the next character as obtained by rdbuf()->sgetc().
Otherwise, returns Traits::eof().
Exceptions
if an error occurred (the error state flag is not
) and
is set to throw for that state.
If an internal operation throws an exception, it is caught and
is set. If
is set for badbit, the exception is rethrown.
Example
Run this code
#include<iostream>#include<sstream>intmain(){std::istringstreams1("Hello, world.");charc1=s1.peek();charc2=s1.get();std::cout<<"Peeked: "<<c1<<" got: "<<c2<<'\n';}Output:
Peeked: H got: H See also
reads one character from the input sequence without advancing the sequence
(public member function of std::basic_streambuf<CharT,Traits>)
extracts characters
(public member function)
unextracts a character
(public member function)