The
std::basic_istream::peek() used to reads the next character from the input stream without extracting it. This function does not accept any parameter, simply returns the next character in the input string. Below is the syntax for the same:
Header File:
#include<iostream>
Syntax:
int peek();
Return Value: The
std::basic_istream::peek() return a next character in the input string.
Below are the programs to understand the implementation of
std::basic_istream::peek() in a better way:
Program 1:
Output:
The first character is: G
and the next is: e
Program 2:
Output:
The first character is: C
and the next is: o
Program 3: