This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
while (cin >> d) does not work if d = int, double, float
- To: libstdc++ at sources dot redhat dot com
- Subject: while (cin >> d) does not work if d = int, double, float
- From: Peter Schmid <schmid at snake dot iap dot physik dot tu-darmstadt dot de>
- Date: Mon, 27 Nov 2000 01:55:19 +0100 (CET)
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