I am trying to concatenate an integer to a known string, and I have found that there are several ways to do it, two of those being:
int num=13;
string str = "Text" + static_cast<ostringstream*>( &(ostringstream() << num) )->str();
or I could also use boost
libraries' lexical_cast
:
int num=13;
string str= "Text" + boost::lexical_cast<std::string>(num);
Is the use of boost::lexical_cast
more efficient in any way, since I already know the conversion type (int
to string
)? Or is static_cast
just as effective, without having to rely on external libraries?
lexical_cast
is much more readable. Note there is alsostd::to_string()
in c++11. – Rheinland