Case (s) where the output buffer will not be hidden?

I iostreamexamine objects and clear the buffer. I know that when output buffers are guaranteed to be flushed and how to explicitly flush the buffer. However, I have never seen a case where the output buffer is not flushed. It seems to me that the output buffer is cleared at the end of each statement, even if I do not use manipulators such as endl, flushand ends.

So, is there any simple example (s) where the output buffer will not (or at least often cannot) be flushed? I feel like I need to see such a case in order to really understand the output buffers.

+4
source share
1 answer

Depends on the system.

:

#include <iostream>
#ifdef WIN32
#include <windows.h>
#define sleep(n) Sleep((n)*1000)
#else
#include <unistd.h>
#endif

using namespace std;

int main()
{
    cout << "This is line 1";
    sleep(4);
    cout << endl;
    cout << "This is line 2" << endl;

    return 0;
}

, , This is line 1, 4 , This is line 2.

Visual Studio Windows, .

Linux Unix 4 , . , .

+3

Source: https://habr.com/ru/post/1688748/


All Articles