| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Global objects | ||||
| Member functions | ||||
(C++11) | ||||
| Formatted input | ||||
| Unformatted input | ||||
basic_istream::peek | ||||
| Positioning | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
int_type peek(); | ||
Behaves asUnformattedInputFunction. After constructing and testing the sentry object, reads the next character from the input stream without extracting it.
Contents |
(none)
Ifgood()==true, returns the next character as obtained byrdbuf()->sgetc().
Otherwise, returnsTraits::eof().
If an internal operation throws an exception, it is caught andbadbit is set. Ifexceptions() is set forbadbit, the exception is rethrown.
#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
| 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] |