[LLVMbugs] [Bug 15154] New: istream discards character when unexpected type is met

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Feb 4 04:13:39 PST 2013


             Bug #: 15154
           Summary: istream discards character when unexpected type is met
           Product: libc++
           Version: 3.2
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: rework11 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

double dd;
std::cin >> dd;

Above code snippet correctly sets cin.fail() when user provides non-double-type
input, such as a character 'x'.

However, when I tried to determine what the problematic input was by the
following code snippet:

char c;
std::cin >> c;

it seems my problematic input 'x' has already discarded and the variable c is
set to ' '; although I expect to see the variable c is set to 'x'.

std::ifstream also behaves wrongly the same way.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list