Namespaces
Variants
Views
Actions

std::basic_istream::peek

From cppreference.com
int_type peek();

After constructing an std::basic_istream::sentry object with noskipws set to true, reads the next character from the input stream without extracting it.

Contents

[edit] Parameters

(none)

[edit] Return value

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

Otherwise, returns Traits::eof().

[edit] 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

[edit] See also

extracts characters
(public member function) [edit]
unextracts a character
(public member function) [edit]