std::basic_istream::unget(3)
π std::basic_istream::unget(3) π
okay so bestie, this page is straight out of the C++ Standard Libary manual, and it's all about std::basic_istream::unget. it's giving "put that one character back" energy, and honestly? obsessed. β¨
πΈ NAME πΈ
std::basic_istream::ungetβstd::basic_istream::unget(yes, the manual says it twice, iconic π )
β¨ Synopsis β¨
basic_istream& unget();
it makes the most recently extracted character available again. literally one-character undo, no cap. π«Ά
First, it clears eofbit. Then, since C++11, unget behaves as UnformattedInputFunction. After constructing and checking the sentry object, if any ios_base::iostate flags are set, the function sets failbit and returns. Otherwise, it calls rdbuf()->sungetc().
If rdbuf()->sungetc() returns Traits::eof(), it calls setstate(badbit).
In any case, it sets the gcount() counter to zero. periodt. π
π Parameters π
(none)β bestie, it takes no arguments. zero. nada. π
π Return value π
*thisβ yup, it returns the stream itself, main character energy. π
π₯ Exceptions π₯
failureif an error occurred (the error state flag is notgoodbit) andexceptions()is set to throw for that state.- If an internal operation throws an exception, it is caught and
badbitis set. Ifexceptions()is set forbadbit, the exception is rethrown.
π§ Example π§
run this code, bestie:
// Run this code
#include <iostream>
#include <sstream>
int main()
{
std::istringstream s1("Hello, world.");
char c1 = s1.get();
if (s1.unget())
{
char c2 = s1.get();
std::cout << "Got: '" << c1 << "'. Got again: '" << c2 <<
"'.\n";
}
}
π Output π
Got: 'H'. Got again: 'H'.
π See also π
sungetcβ moves the next pointer in the input sequence back by one (public member function ofstd::basic_streambuf<CharT,Traits>)getβ extracts characters (public member function)peekβ reads the next character without extracting it (public member function)putbackβ puts a character into input stream (public member function)
kisses and slay, bestie πβ¨ β source: http://cppreference.com; version/date: 2024.06.10; page: std::basic_istream::unget(3). π«Άπ
π¦ 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