https://bugzilla.novell.com/show_bug.cgi?id=416094
User matz@novell.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=416094#c2
Michael Matz changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
--- Comment #2 from Michael Matz 2008-08-11 10:14:10 MDT ---
You run into one of the ugliest things in STL: locales. Congratulation!
The basic problem with your testprogram is, that the string (and hence
inputstream) contains "4 ", i.e. with a trailing space. Now, in the fr_FR
locale (and some others) the thousands separator actually is ' ', the space
character.
The ISO C++ standard specifies, that if a number is parsed, it's done
according to the locale, including checking the grouping of thousands
for consistency, if the locale requests that. The fr_FR locale specifies a
grouping by three characters per group (only the first group may not follow
that of course). A _trailing_ thousands separator is invalid in any case.
In de_DE for instance the separator is '.' and you would get the same error
with an input string of "4." parsed as int.
What's ugly about this, is of course that this is "only" a whitespace, and
hence could validly be ignored and not parsed as thousands separator.
Unfortunately that's what is required by the ISO standard :-(
So, only ever feed pre-separated tokens into the STL stream parsers.
For reference see 22.2.2.1.2 rule 12 that specifies the requirement of grouping
checks, and 22.2.3.1.2 rule 3, for what consistency means.
FWIW, you can use sscanf, that works as expected even in the presence of
trailing separators. See the "'" flag character for input conversion, e.g.
sscanf (input, "%'d", ...)
will parse numbers including thousands separators (according to current
locale) and be not anal about checking.
Again, congratulation :-) INVALID.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.