Namespaces
Variants

std:: ws

From cppreference.net
< cpp ‎ | io ‎ | manip
헤더 파일에 정의됨 <istream>
template < class CharT, class Traits >
std:: basic_istream < CharT, Traits > & ws ( std:: basic_istream < CharT, Traits > & is ) ;

입력 스트림에서 선행 공백 문자를 제거합니다.

UnformattedInputFunction 처럼 동작하지만, is. gcount ( ) 은 수정되지 않습니다. sentry 객체를 생성하고 검사한 후, 다음 조건 중 하나가 발생할 때까지 스트림에서 문자를 추출하여 버립니다:

  • 입력 시퀀스에서 파일 끝 조건이 발생하는 경우(이 경우 함수는 setstate ( eofbit ) 를 호출하지만 failbit 을 설정하지 않음; 이는 ws 호출 전에 is eofbit 이 이미 설정된 경우에는 적용되지 않으며, 이 경우 sentry 객체의 생성이 failbit 을 설정하게 됨).
  • 입력 시퀀스에서 다음으로 사용 가능한 문자 c std:: isspace ( c, is. getloc ( ) ) 에 의해 결정된 공백 문자가 아닙니다. 비공백 문자는 추출되지 않습니다.

이것은 입력 전용 I/O 조정자이며, 다음과 같은 표현식으로 호출될 수 있습니다. in >> std :: ws 어떤 in 이든 std::basic_istream 타입에 대해.

목차

매개변수

is - 입력 스트림에 대한 참조

반환값

is (연속된 공백 추출 후 스트림에 대한 참조).

참고 사항

만약 eofbit 이 호출 전에 스트림에 설정되어 있다면, sentry 객체의 생성이 failbit 을 설정할 것입니다.

예제

#include <iomanip>
#include <iostream>
#include <istream>
#include <sstream>
#include <string>
int main()
{
    for (const char* str : {"     #1 test", "\t #2 test", "#3 test"})
    {
        std::string line;
        std::getline(std::istringstream{str}, line);
        std::cout << "getline returns:\t" << std::quoted(line) << '\n';
        std::istringstream iss{str};
        std::getline(iss >> std::ws, line);
        std::cout << "ws + getline returns:\t" << std::quoted(line) << '\n';
    }
}

출력:

getline returns:	"     #1 test"
ws + getline returns:	"#1 test"
getline returns:	"	 #2 test"
ws + getline returns:	"#2 test"
getline returns:	"#3 test"
ws + getline returns:	"#3 test"

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 415 C++98 std::ws 호출이 sentry 객체를 생성하지 않을 수 있음
(다른 입력 함수들과 불일치)
sentry 객체 생성을
요구함

참고 항목

주어진 문자를 찾을 때까지 문자를 추출하고 버림
( std::basic_istream<CharT,Traits> 의 public member function)