We help IT Professionals succeed at work.

disable cout buffering

paulchen
paulchen asked
on
Medium Priority
1,353 Views
Last Modified: 2012-06-27
How can I disable the buffering of output from cout?

Thank you!
Comment
Watch Question

Commented:
use:

cout.setf (ios::unitbuf, 0);

This forces a buffer of 1 char, which is actually no buffer at all.


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
hello md!

thank you for your answer.
unfortunately, it didn't work. it still gets all buffered and
output after program termination.

Commented:
I've never seen this before.  What platform/compiler?

BTW, I recall that cout is unitbuf by default.
Does "cerr" behave like you want it to (ie. unbuffered?) If it does not, then the problem could be with the OS, not the libraries you are using. (cerr is tied to fd 2 (stderr) instead of fd 1 (stdout) and is supposed to be unbuffered, though both are based the same parent class (as far as I know, may be implementation dependant)).

"clog" is supposed to be an unbuffered "cerr".
How do they do it? (tracking this doen might help)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.