Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::basic_istream::unget(3)  C++ Standard Libary std::basic_istream::unget(3)

NAME
       std::basic_istream::unget - std::basic_istream::unget

Synopsis
	  basic_istream& unget();

	  Makes	the most recently extracted character available	again.

	  First	clears eofbit. (since C++11)

	  Then	the  function  behaves as UnformattedInputFunction. After con-
       structing and
	  checking the sentry object, if any ios_base::iostate flags are  set,
       the function
	  sets failbit and returns. Otherwise, calls rdbuf()->sungetc().

	  If rdbuf()->sungetc()	returns	Traits::eof(), calls setstate(badbit).

	  In any case, sets the	gcount() counter to zero.

Parameters
	  (none)

Return value
	  *this

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  bad-
       bit 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.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     of    std::basic_stream-
       buf<CharT,Traits>)
	  get	  extracts characters
		  (public member function)
	  peek	  reads	the next character without extracting it
		  (public member function)
	  putback puts character into input stream
		  (public member function)

http://cppreference.com		  2022.07.31	  std::basic_istream::unget(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::wistream::unget&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help