delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/05/02/02:06:30

From: jkubicky AT cco DOT caltech DOT edu (Joseph J. Kubicky)
Subject: Problem with cout in 1.06
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Fri, 1 May 92 23:01:26 PDT
Status: O



I'm found a little problem with the cout<< stuff in 1.06.  I don't have time
(nor the expertise, really) to track it down myself, but someone might be
interested.  Basically, it involves redirecting the output of a c++ prog to
a file.

Here is the program:

#include <stream.h>
#include <stdio.h>

main()
{
	for(int i=0; i < 500; ++i)
//		printf("ABCDEFG  %d\n", i);
		cout<<"ABCEFG  "<<i<<"\n";
}

If I compile it like it is (using cout<< instead of printf), and then run
it normally (i.e. go32 t1), I get the expected:

. 
. 
. 
ABCDEFG  498
ABCDEFG  499
C> (program done).

But if I redirect the output:

go32 t1 >t1.out,

the file ends with something like:

ABCDEFG  478
ABCDEF(eof)

If I use printf (comment out cout<<), the file looks like what we would
expect.  The difference in the sizes of the files produced is 6890-6110=
770.  If I shorten the output to 300 lines, the difference is 753 bytes.
Looks like a buffer isn't being flushed.


Jay Kubicky
jkubicky AT cco DOT caltech DOT edu


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019