Closed stilgarpl closed 2 years ago
In case someone is puzzled by this same issue:
The check ss.good()
is not correct in this context. If eofbit
is set, ss.good() == false
. The correct check is !ss.fail()
, which doesn't care if eofbit
is set or not.
I'm using this code to parse date (ss is std::stringstream parameter with date string)
When format is "%F" it correctly parses dates with leading zeroes, for example "2020-05-09", but it fails on dates without leading zeroes ("2020-5-9"). But if I change the format to full "%Y-%m-%d", it parses both dates correctly. Surprisingly, it works when one leading zero is omitted ("2020-5-09" parses correctly). https://en.cppreference.com/w/cpp/chrono/parse says that both formats should be equivalent, so it looks like a bug.
Here is proof: https://wandbox.org/permlink/blYXeBZbmDH9HvQT