Solved

disable cout buffering

Posted on 1997-06-10
4
1,126 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 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now