Topic: cout vs printf


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Mon, 1 Nov 1993 09:53:42 GMT
Raw View
In article <2a9m8j$9hc@genesis.ait.psu.edu> PNC@ECL.PSU.EDU (Pramod N Chivate) writes:
>i have observed this strange phenomena about "cout" and "printf" statements.
>if both are used in a single program, the printf statements are written as the
>statement gets executed but "cout" statements are all written after the
>end of execution of the program. Ay clues, comments, suggestions are welcome
>to overcome this problem.

I know that in many existing implementations, cout and stdout each have
their own separate buffers.  That fact may partially explain what you
are seeing.

Mind you I have no idea *why* cout and stdout should have separate buffers.
I have always considered that to be merely a sign of poor quality implementa-
tions myself.  I'd like to be able to use both streams and stdio in the same
program and get something approaching reasonable results.  Likewise, I'd
like to be able to use malloc/free *and* new/delete within the same program
without things going haywire.

--

-- Ronald F. Guilmette, Sunnyvale, California -------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------




Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Mon, 1 Nov 1993 10:09:54 GMT
Raw View
In article <ANDREW.93Oct25155940@srsund.shlrc.mq.edu.au> andrew@srsuna.shlrc.mq.edu.au writes:
>In article <2a9m8j$9hc@genesis.ait.psu.edu> PNC@ECL.PSU.EDU (Pramod N Chivate) writes:
>
>>  i have observed this strange phenomena about "cout" and "printf" statements.
>>  if both are used in a single program, the printf statements are written as the
>>  statement gets executed but "cout" statements are all written after the
>>  end of execution of the program. Ay clues, comments, suggestions are welcome
>>  to overcome this problem.
>>
>
>The stream used by cout is buffered, printf is not...

Printf is not buffered, eh?  What a shock!

Who's going to break the news to all of those millions of C programmers
out there who think that it *is* buffered?

:-)

--

-- Ronald F. Guilmette, Sunnyvale, California -------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------




Author: davisonj@bnr.ca (Jack Wasserman)
Date: 2 Nov 1993 18:22:46 -0600
Raw View
        In article <ANDREW.93Oct25155940@srsund.shlrc.mq.edu.au>,
andrew@srsuna.shlrc.mq.edu.au wrote:
>The stream used by cout is buffered, [sic] printf is not...

        This is not entirely true.  See American National Standard X3.159-1989,
Section 4.9.3 for details.
--
+-------+ | I: How many wives do you have?  | I: Are you telling me the truth?
|John   | | Koresh: (sighs) One... _One_.   | K: I'm telling you the truth.
|Davison| | I: Have you committed adultery? | I: Have you beaten children?
+-------+ | K: No. I don't commit adultery. | K: No. I do not beat children.