std::basic_istream::peek(3)
π std::basic_istream::peek(3) π
okay bestie, this page is from the C++ Standard Libary (yes, spelled like that in the manual β iconic π). Itβs all about std::basic_istream::peek, and itβs lowkey one of the cutest little stream functions.
πΈ NAME πΈ
std::basic_istream::peek β std::basic_istream::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. peek only, no take β look but donβt touch energy πβ¨.
π Parameters π
(none)β bestie, there are literally no parameters here. π
π 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.
π¨ bestie, exceptions can happen β this is the part where you check your exception settings, fr fr.
π Example π
// Run this code
#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 π
Peeked: H got: H
π See also π
sgetcβ reads one character from the input sequence without advancing the sequence (public member function ofstd::basic_streambuf<CharT,Traits>)getβ extracts characters (public member function)ungetβ unextracts a character (public member function)
mwah π β sourced from http://cppreference.com, version 2024.06.10, and this iconic page is std::basic_istream::peek(3). bye bestie π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms