std::basic_istream<CharT,Traits>::peek

Behaves as UnformattedInputFunction. After constructing and testing the sentry object, reads the next character from the input stream without extracting it.

# Declarations

int_type peek();

# Return value

If good() == true, returns the next character as obtained by rdbuf()->sgetc().

# Example

#include <iostream>
#include <sstream>
 
int main()
{
    std::istringstream s1("Hello, world.");
    char c1 = s1.peek();
    char c2 = s1.get();
    std::cout << "Peeked: " << c1 << " got: " << c2 << '\n';
}

# See also