Note that the article doesn't mention to_string
, which is the preferred C++11 way to convert an int
to a string
. But it does point out an issue -- you can assign an int
to a string
, including by accident.
Dangerous int-to-string conversions
by Andrzej Krzemieński
From the article:
And now, because
int
is implicitly convertible tochar
, our unexpected conversion fromint
tostd::string
‘works’ (under some definition of ‘work’)...
Add a Comment
Comments are closed.