Opened 11 years ago
Closed 11 years ago
#6094 closed Bugs (invalid)
1 secondALPHA should be an invalid input for a duration.
Reported by: | viboes | Owned by: | viboes |
---|---|---|---|
Milestone: | To Be Determined | Component: | chrono |
Version: | Boost 1.47.0 | Severity: | Problem |
Keywords: | Cc: |
Description
I expect the following input to be an invalid
1 seconde
to fail (in English). But it works without scanning the last 'e'.
It seems that this is the current practice in the standard
But this goes against current practice:
#include <sstream> #include <iostream> int main() { std::istringstream in("1e+10"); int s = 10; in >> s; if (!in.fail()) std::cout << s << '\n'; else std::cout << "failed\n"; char c = 0; in >> c; if (!in.fail()) std::cout << c << '\n'; else std::cout << "failed\n"; }
Outputs
1 e
I think, however that this is a different case, as integers and letters could be go together.
I can understand that after
1 second
any non alpha character could be accepted, but not an alphabetic.
The solution could be simple. Once the unit keyword match, a check on the next character (if one) is done to ensure that isalpha(c) is false.
Change History (2)
comment:1 by , 11 years ago
Component: | None → chrono |
---|---|
Status: | new → assigned |
comment:2 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
It seems that the standard io works this way (no need to have white space separators, so fixed as invalid.