Namespaces
Variants

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

From cppreference.net
int_type peek ( ) ;

UnformattedInputFunction 으로 동작합니다. sentry 객체를 구성하고 테스트한 후, 입력 스트림에서 다음 문자를 추출하지 않고 읽습니다.

목차

매개변수

(없음)

반환값

만약 good ( ) == true 이면, rdbuf ( ) - > sgetc ( ) 로 얻은 다음 문자를 반환합니다.

그렇지 않으면, Traits :: eof ( ) 를 반환합니다.

예외

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

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

예제

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

출력:

Peeked: H got: H

참고 항목

입력 시퀀스에서 한 문자를 읽되 시퀀스를 진행하지 않음
( std::basic_streambuf<CharT,Traits> 의 public member function)
문자를 추출함
(public member function)
문자를 되돌림
(public member function)