Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic


Returns the next character to be read.

int_type peek( );

The next character that will be read.

The unformatted input function extracts an element, if possible, as if by returning rdbuf ->sgetc. Otherwise, it returns traits_type::eof.

// basic_istream_peek.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

int main( ) 
   char c[10], c2;
   cout << "Type 'abcde': ";

   c2 = cin.peek( );
   cin.getline( &c[0], 9 );

   cout << c2 << " " << c << endl;
Type 'abcde': abcde
a abcde

Header: <istream>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.