std::basic_istream<CharT,Traits>:: ignore
|
basic_istream
&
ignore
(
std::
streamsize
count
=
1
, int_type delim
=
Traits
::
eof
(
)
)
;
|
||
입력 스트림에서 문자를 추출하고 버리며, delim 을 포함할 때까지 계속합니다.
ignore
는
UnformattedInputFunction
로 동작합니다. sentry 객체를 생성하고 검사한 후, 다음 조건 중 하나가 발생할 때까지 스트림에서 문자를 추출하여 버립니다:
- count 개의 문자가 추출되었습니다. 이 테스트는 특별한 경우인 count 가 std:: numeric_limits < std:: streamsize > :: max ( ) 와 같을 때 비활성화됩니다.
- 입력 시퀀스에서 파일 끝 조건이 발생하는 경우, 이때 함수는 setstate ( eofbit ) 를 호출합니다.
- 입력 시퀀스에서 다음으로 사용 가능한 문자 c 가 Traits :: eq_int_type ( Traits :: to_int_type ( c ) , delim ) 에 의해 결정된 대로 delim 인 경우. 구분자 문자는 추출되어 폐기됩니다. 이 검사는 delim 이 Traits :: eof ( ) 인 경우 비활성화됩니다.
목차 |
매개변수
| count | - | 추출할 문자 수 |
| delim | - | 추출을 중지할 구분 문자. 해당 문자도 함께 추출됨 |
반환값
* this
예외
내부 연산에서 예외가 발생하면, 해당 예외는 포착되고
badbit
이 설정됩니다. 만약
exceptions()
가
badbit
에 대해 설정되어 있다면, 예외가 재발생됩니다.
예제
다음 예제는
ignore
를 사용하여 숫자가 아닌 입력을 건너뛰는 방법을 보여줍니다:
#include <iostream> #include <limits> #include <sstream> constexpr auto max_size = std::numeric_limits<std::streamsize>::max(); int main() { std::istringstream input("1\n" "some non-numeric input\n" "2\n"); for (;;) { int n; input >> n; if (input.eof() || input.bad()) break; else if (input.fail()) { input.clear(); // unset failbit input.ignore(max_size, '\n'); // skip bad input } else std::cout << n << '\n'; } }
출력:
1 2
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 172 | C++98 | count 의 타입이 int 로 잘못 지정됨 | std::streamsize 로 수정됨 |
참고 항목
|
문자 추출
(public member function) |
|
|
지정된 문자를 찾을 때까지 문자 추출
(public member function) |