Ok, I'm working on my Operating Systems assignment. I need to write a microkernel which is able to do some basic stuff with threads, semaphores, events, etc. BCC 3.1 is imitating my system environment. Classical debugging is really not of use. I'm debugging in cout style. Problem is weird behavior of cout. It writes out in blocks or something. If I do, like, 40 couts it writes everything out. If I do 39 of them, it doesn't write any of them. On other hand if i do between 40 and 79 couts, it still writes only first 40, but if I do 80 of them, they're all ok, etc. Numbers are not exact, I'm not sure what's the number really. But I have also noticed that changing the length of string that is cout-ed effects the same way. Only I don't know how many characters equals one cout call. Additional information available upon request. Thanks in forward.
Asked
Active
Viewed 325 times
0
-
1`cout` is buffered. Either `flush()` it when needed, or append `endl`s which flush, or write to `cerr` instead, which is unbuffered. – Kerrek SB Jul 27 '11 at 13:38
-
cerr doesn't work. flush(cout) has no effect. I mean, cerr does write out, but in the same manner as cout. – maricn Jul 27 '11 at 13:41
-
Then your environment is probably buffering too. Btw. I think you mean `std::cout.flush()` and not `flush(std::cout)`? – Nobody moving away from SE Jul 27 '11 at 13:42
-
flushing isn't working. How could i find out if it is buffering? – maricn Jul 27 '11 at 13:48
1 Answers
1
sounds like buffering regardless of the fact std::cout
shouldn't buffer output. in any case you can try flushing cout
by
std::cout.flush();
or
std::cout << std::flush;
or
std::cout << std::endl;
or even by disabling buffering:
std::cout.rdbuf()->pubsetbuf(0, 0);

Andriy Tylychko
- 15,967
- 6
- 64
- 112
-
no effect at all from flushing... i've tried last line, but got compiler error: pubsetbuf is not a member of streambuf. – maricn Jul 27 '11 at 13:47