This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/5820: EOF not handled correctly on input
- From: jm at bourguet dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 3 Mar 2002 19:09:02 -0000
- Subject: libstdc++/5820: EOF not handled correctly on input
- Reply-to: jm at bourguet dot org
>Number: 5820
>Category: libstdc++
>Synopsis: EOF not handled correctly on input
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Mar 03 11:16:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: jm@bourguet.org
>Release: gcc-3.0.2
>Organization:
>Environment:
Debian Linux
>Description:
On all Unix variants I've tried, programs taking their input from a
terminal consider two CTRL-D (this key can be changed with stty, but
I'll use CTRL-D) in a row or one CTRL-D just at the beginning of a
line as an end of file indication.
With the C++ library furnished with gcc 3.0.2, executing:
#include <iostream>
#include <istream>
#include <ostream>
int main()
{
int i;
char c;
std::cout << "Enter an integer: ";
std::cin >> i;
if (!std::cin) {
std::cerr << "Unexpected read problem\n";
return 1;
}
std::cout << '\n' << "std::cin.eof()=" << std::cin.eof() << '\n';
std::cout << "The number was: " << i << '\n';
std::cin >> c;
if (std::cin) {
std::cerr << "Could read " << c << " after the number!\n";
}
}
on a Linux box with input and output directed to a terminal, I had to
type 4 times CTRL-D after 5 to get the expected result:
Enter an integer: 5
std::cin.eof()=1
The number was: 5
If I type "5", two or three CTRL-D and "a", I get:
Enter an integer: 5a
std::cin.eof()=0
The number was: 5
Could read a after the number!
>How-To-Repeat:
See description
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: