Namespaces
Variants

std:: unitbuf, std:: nounitbuf

From cppreference.net
< cpp ‎ | io ‎ | manip
Input/output manipulators
Floating-point formatting
Integer formatting
Boolean formatting
Field width and fill control
Other formatting
Whitespace processing
Output flushing
unitbuf nounitbuf
Status flags manipulation
Time and money I/O
(C++11)
(C++11)
(C++11)
(C++11)
Quoted manipulator
(C++14)
헤더 파일에 정의됨 <ios>
(1)
std:: ios_base & nounitbuf ( std:: ios_base & str ) ;
(2)

출력 작업 후 출력 스트림의 자동 플러싱을 활성화하거나 비활성화합니다. 입력에는 영향을 미치지 않습니다.

1) 스트림 str 에서 unitbuf 플래그를 활성화합니다. 마치 str. setf ( std:: ios_base :: unitbuf ) 를 호출한 것처럼 동작합니다.
2) 스트림 str 에서 unitbuf 플래그를 비활성화합니다. 마치 str. unsetf ( std:: ios_base :: unitbuf ) 를 호출한 것처럼 동작합니다.

이것은 I/O 조작자이며, out << std :: unitbuf 와 같은 표현식으로 std::basic_ostream 타입의 모든 out 에 대해 호출될 수 있으며, in >> std :: unitbuf 와 같은 표현식으로 std::basic_istream 타입의 모든 in 에 대해서도 호출될 수 있습니다.

목차

참고 사항

플러싱은 std::basic_ostream::sentry 객체의 소멸자에서 수행되며, 이는 str. rdbuf ( ) - > pubsync ( ) 를 호출합니다. 단, str. flags ( ) & std:: ios_base :: unitbuf true 인 경우에 한합니다.

표준 출력 객체 std::cerr std::wcerr 는 기본적으로 unitbuf 비트가 설정되어 있습니다.

매개변수

str - I/O 스트림에 대한 참조

반환값

str (조작 후 스트림에 대한 참조).

예제

std::unitbuf 나 다른 명시적 플러시 없이는 출력은 동일하지만, 실시간으로 표시되지 않습니다.

#include <chrono>
#include <iostream>
template<typename Diff>
void log_progress(Diff d)
{
    std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(d)
              << " ... ";
}
int main()
{
    volatile int sink = 0;
    std::cout << std::unitbuf; // enable automatic flushing
    const auto start = std::chrono::high_resolution_clock::now();
    for (int j = 0; j < 5; ++j)
    {
        for (int n = 0; n < 10000; ++n)
            for (int m = 0; m < 20000; ++m)
                sink += m * n; // do some work
        log_progress(std::chrono::high_resolution_clock::now() - start);
    }
    std::cout << '\n';
}

출력:

571ms ... 1146ms ... 1722ms ... 2294ms ... 2865ms ...

참고 항목

출력 스트림을 플러시함
(함수 템플릿)
' \n ' 를 출력하고 출력 스트림을 플러시함
(함수 템플릿)