Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

disable cout buffering

Posted on 1997-06-10
4
Medium Priority
?
1,241 Views
Last Modified: 2012-06-27
How can I disable the buffering of output from cout?

Thank you!
0
Comment
Question by:paulchen
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
md041797 earned 100 total points
ID: 1163881
use:

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

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


0
 

Author Comment

by:paulchen
ID: 1163882
hello md!

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

0
 
LVL 4

Expert Comment

by:md041797
ID: 1163883
I've never seen this before.  What platform/compiler?

BTW, I recall that cout is unitbuf by default.
0
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1163884
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)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question