stdin redirection problem

From: Alexandr Malusek (malusek@hroch.ujf.cas.cz)
Date: Wed Jul 29 1998 - 17:17:42 MEST


Dear Rooters,

The stdin redirection doesn't seem to work OK for macros using cin,
while scanf() seems to work OK. Is it a feature or a bug? It would be
nice if the stdin could be redirected for macros using cin, too.

An example:
root [0] .x m1.C < d1.dat        # The first execution is OK
1
2
root [1] .x m1.C < d1.dat        # Subsequent executions fail (no output)
root [2] cin.good()
(int)0
root [3] .x m2.C < d1.dat        # m2.C uses scanf() 
1
2
root [4] .x m2.C < d1.dat        # Subsequent executions are OK
1
2

$ cat m1.C
{
#include <iostream.h>

  Int_t n;
  while (cin >> n)
    cout << n << endl;
}

$ cat m2.C
{
#include <stdio.h>

  Int_t n;
  while (scanf("%d", &n) == 1)
    printf("%d\n", n);
}

$ cat d1.dat
1
2

ROOT 2.00/09, Linux RedHat 4.2.

Regards,
---------------------------------------------------------------------------
Alexandr Malusek                                 
Nuclear Physics Institute                        e-mail: malusek@ujf.cas.cz
Department of Radiation Dosimetry                   tel: +420 2 66311783
Na Truhlarce 39/64, 180 86 Praha 8, Czech Republic  fax: +420 2 823344   
---------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET