r/learncpp • u/mutual_coherence • Sep 09 '20
What actually is buffering?
I learned that std::cout has a buffered output, while std::cerr is unbuffered.
I don't actually know what buffering is. I've somewhat guessed that it's analogous to the buffering during a video stream. If all the data isn't ready (has not arrived) it will not show anything until it's ready to show. And that somehow, C++ has a way for checking that the data is ready before the output will appear on my console.
Is this guess correct?
5
Upvotes
View all comments
Show parent comment
4
u/CuriousMachine Sep 10 '20
Computers are still slow at this if you're piping a lot of data between programs. Think of CLI programs like cat or grep. Buffering cout helps by doing fewer, larger writes.