Namespaces
Variants
Views
Actions

std::basic_istream::peek

From cppreference.com
< cpp‎ | io‎ | basic istream
Revision as of 21:16, 2 November 2012 by P12bot (Talk | contribs)

int_type peek();

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

Contents

Parameters

(none)

Return value

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

Otherwise, returns Traits::eof().

Example

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

Output:

Peeked: H got: H

See also

Template:cpp/io/basic istream/dcl list getTemplate:cpp/io/basic istream/dcl list unget