std::basic_istream<CharT,Traits>::peek (3) - Linux Manuals
std::basic_istream<CharT,Traits>::peek: std::basic_istream<CharT,Traits>::peek
Command to display std::basic_istream<CharT,Traits>::peek
manual in Linux: $ man 3 std::basic_istream<CharT,Traits>::peek
NAME
std::basic_istream<CharT,Traits>::peek - std::basic_istream<CharT,Traits>::peek
Synopsis
int_type peek();
Behaves as UnformattedInputFunction. After constructing and testing the sentry object, reads the next character from the input stream without extracting it.
Parameters
(none)
Return value
If good() == true, returns the next character as obtained by rdbuf()->sgetc()
Otherwise, returns Traits::eof().
Exceptions
failure 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.
Example
// Run this code
#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
reads one character from the input sequence without advancing the sequence
sgetc (public member function of std::basic_streambuf<CharT,Traits>)
extracts characters
get (public member function)
unextracts a character
unget (public member function)
Pages related to std::basic_istream<CharT,Traits>::peek
- std::basic_istream<CharT,Traits>::putback (3) - std::basic_istream<CharT,Traits>::putback
- std::basic_istream<CharT,Traits>::basic_istream (3) - std::basic_istream<CharT,Traits>::basic_istream
- std::basic_istream<CharT,Traits>::gcount (3) - std::basic_istream<CharT,Traits>::gcount
- std::basic_istream<CharT,Traits>::get (3) - std::basic_istream<CharT,Traits>::get
- std::basic_istream<CharT,Traits>::getline (3) - std::basic_istream<CharT,Traits>::getline
- std::basic_istream<CharT,Traits>::ignore (3) - std::basic_istream<CharT,Traits>::ignore
- std::basic_istream<CharT,Traits>::operator= (3) - std::basic_istream<CharT,Traits>::operator=
- std::basic_istream<CharT,Traits>::operator>> (3) - std::basic_istream<CharT,Traits>::operator>>
- std::basic_istream<CharT,Traits>::read (3) - std::basic_istream<CharT,Traits>::read
- std::basic_istream<CharT,Traits>::readsome (3) - std::basic_istream<CharT,Traits>::readsome
- std::basic_istream<CharT,Traits>::seekg (3) - std::basic_istream<CharT,Traits>::seekg
- std::basic_istream<CharT,Traits>::sentry (3) - std::basic_istream<CharT,Traits>::sentry
- std::basic_istream<CharT,Traits>::swap (3) - std::basic_istream<CharT,Traits>::swap
- std::basic_istream<CharT,Traits>::sync (3) - std::basic_istream<CharT,Traits>::sync
- std::basic_istream<CharT,Traits>::tellg (3) - std::basic_istream<CharT,Traits>::tellg
- std::basic_istream<CharT,Traits>::unget (3) - std::basic_istream<CharT,Traits>::unget
- std::basic_istream<CharT,Traits>::~basic_istream (3) - std::basic_istream<CharT,Traits>::~basic_istream
- std::basic_istream (3) - std::basic_istream
- std::basic_istream_sentry (3)
- std::basic_istringstream (3) - std::basic_istringstream