another oddity with file streams

scott snyder snyder@fnal.gov
Sat Apr 1 00:00:00 GMT 2000


hi -

Here's another oddity with file streams in the cvs version
of libstdc++.  (Tested on a gnu/linux-386 platform.)

-- z5.cc -----------------------------------------------------------------
#include <iostream>
#include <unistd.h>

int main ()
{
  std::cerr << "line 1\n";
  std::cerr.flush ();
  write (2, "line 2\n", 7);
  std::cerr << "line 3\n";
  return 0;
}
--------------------------------------------------------------------------

If i just run this with the output going to the terminal, it works fine:

$ ./z5
line 1
line 2
line 3


But if i try to redirect the output to a file, the output from the write()
gets lost:

$ ./z5 >& xx
$ cat xx
line 1
line 3


[This showed up in a C++ program -- itself using iostreams for output --
which was calling an older library written in plain C -- which
was using write (2, ...) to output error messages.]

sss


More information about the Libstdc++ mailing list