This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

while (cin >> d) does not work if d = int, double, float


Reading numbers from cin or from a file in a loop does not work, since eof is
not processed correctly.
Running the following program on my i686-pc-linux-gnu box (GLIBC 2.1.3
gcc-20001120) 

cat tr.C
#include <iostream>

int main()
{
    int i;
    while (std::cin >> i)
        std::cout << i << '\n';
}

-- 
Generates the following output, when I type e.g. 12 and the press ^D.
peter@kiste:~/> g++ tr.C
peter@kiste:~/>./a.out 
12 (^D is given)
12
12
12
12
12
12
12
12
12
12
12
repeated until the program is terminated by a signal.
It does not matter if the variable is an int, a float, a short, or a double;
reading a string or a char works though. Reading former types from a file
does not work with a while loop of the kind while (file >> i) either.

I believe this should be fixed. (I'm writing to this list since the original
prs-mailing list seems to be dead). 

Peter Schmid


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]