Namespaces
Variants

std::basic_istream<CharT,Traits>:: unget

From cppreference.net
basic_istream & unget ( ) ;

가장 최근에 추출된 문자를 다시 사용할 수 있게 합니다.

먼저 eofbit 을 지웁니다. 그런 다음 (C++11부터) unget UnformattedInputFunction 으로 동작합니다. sentry 객체를 구성하고 검사한 후, ios_base::iostate 플래그가 설정되어 있으면 함수는 failbit 를 설정하고 반환합니다. 그렇지 않으면 rdbuf ( ) - > sungetc ( ) 을 호출합니다.

만약 rdbuf ( ) - > sungetc ( ) Traits :: eof ( ) 를 반환하면, setstate ( badbit ) 를 호출합니다.

어떤 경우에도 gcount() 카운터를 0으로 설정합니다.

목차

매개변수

(없음)

반환값

* this

예외

failure if an error occurred (the error state flag is not goodbit ) and exceptions() is set to throw for that state.

내부 연산에서 예외가 발생하면, 해당 예외는 포착되고 badbit 이 설정됩니다. 만약 exceptions() badbit 에 대해 설정되어 있다면, 예외가 재발생됩니다.

예제

#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";
    }
}

출력:

Got: 'H'. Got again: 'H'.

참고 항목

입력 시퀀스의 다음 포인터를 하나 뒤로 이동
( std::basic_streambuf<CharT,Traits> 의 public member function)
문자를 추출
(public member function)
다음 문자를 추출하지 않고 읽음
(public member function)
입력 스트림에 문자를 넣음
(public member function)