VOOZH about

URL: https://www.geeksforgeeks.org/cpp/basic_istreampeek-in-c-with-examples/

⇱ basic_istream::peek() in C++ with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

basic_istream::peek() in C++ with Examples

Last Updated : 15 Jul, 2025
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:
Output:
The first character is: L 
and the next is: a 
after that next is: p
Reference: https://cplusplus.com/reference/istream/basic_istream/peek/
Comment
Article Tags: