A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../io/basic_stringbuf/../basic_istream/peek.html below:

std::basic_istream<CharT,Traits>::peek - cppreference.com

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

[edit] Parameters

(none)

[edit] Return value

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

Otherwise, returns Traits::eof().

[edit] Exceptionsfailure

if an error occurred (the error state flag is not

goodbit

) and

exceptions()

is set to throw for that state.

If an internal operation throws an exception, it is caught and badbit is set. If exceptions() is set for badbit, the exception is rethrown.

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

Output:

[edit] See also reads one character from the input sequence without advancing the sequence
(public member function of std::basic_streambuf<CharT,Traits>) [edit] extracts characters
(public member function) [edit] unextracts a character
(public member function) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4