Again, is cout buffered or unbuffered ?
-
Tuesday, January 22, 2013 6:21 PM
On this thread it was shown that cout is unbuffered when directed to the console. However when I run this code I get that the default value for the std::ios_base::unitbuf flag for the stream cout is unset, which says the contrary, i.e., that cout is buffered.
#include <iostream> int main() { // This prints "unset" for the default value of the flag
// std::ios_base::unitbuf for the stream cout std::cout << "Flag unitbuf " <<
(std::cout.flags() & std::ios_base::unitbuf ? "set" : "unset") << '\n'; }
All Replies
-
Tuesday, January 22, 2013 7:06 PM
On 1/22/2013 1:21 PM, Ayrosa wrote:
On this thread <http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/415aac5f-0bf1-4ad1-a673-597ac042d36f> it was shown that cout is unbuffered when directed to the console. However when I run this code I get that the default value for the std::ios_base::unitbuf flag for the stream/cout/ is /unset/, which says the contrary, i.e., that /cout/ is buffered.
unitbuf flag controls whether the buffer is flushed after each output operation. As such, it only affects buffered streams - if there's no buffer, there's nothing to flush. This is similar to how the output of printf() appears on the console immediately, without you having to call fflush(stdout).
Igor Tandetnik
- Marked As Answer by Ayrosa Tuesday, January 22, 2013 11:26 PM
-
Tuesday, January 22, 2013 10:02 PM>Again, is cout buffered or unbuffered ?
You were given the definitive answer in the other
thread from the Microsoft employee who maintains
the Standard Library and iostreams.
- Wayne -
Wednesday, January 23, 2013 4:19 PM
WayneAKing wrote:
The problem Wayne is that MS own docs contradict what Mr. Lavavej said. But I have no more doubts in my mind that cout is unbuffered ! Thanks.
You were given the definitive answer in the other
thread from the Microsoft employee who maintains
the Standard Library and iostreams.

