Open aphecetche opened 1 day ago
it is mostly on purpose. Internally it uses std::strtoll
to do the conversion and it has a check to make sure that is converts the entire string to an integer or other number. std::stoi
ignores trailing characters as well so it converts " 523badNUMBER" just as well as "523" This is generally not what is desired, so the general philosophy has been that if it can't use all the characters in the conversion then something is wrong.
The exact question of whether trailing spaces should be allowed is probably debatable.
ok, I see. Considering that "523badNUMBER" is not a valid number indeed makes sense to me.
But rejecting "523 " is a bit more surprising (and probably less obvious to spot from the user point of view).
A very simple example (using version 2.4.2) "fails" when called with
-i "42 "
(note the extra space at the end of the string), but works fine for e.g.-i " 42"
(space before the integer) (and of course for the more natural way of calling it directly with an integer, e.g.-i 42
Is that a feature or a bug ? Knowing that e.g.
std::stoi
convert both " 42" and "42 " just fine, I'd call it a bug, but there might be something obvious I'm missing here ?see e.g. https://godbolt.org/z/jad4MfsKP to run it