Is this correct for all C++ compilers? Or should I cast to int first instead?
int8_t i = -128;
std::string = boost::lexical_cast<std::string>((int16_t)i)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
std::to_stringfunction to do this:http://en.cppreference.com/w/cpp/string/basic_string/to_string
NOTE:
I assumed C++11 because fixed width types where only added in C++11
http://en.cppreference.com/w/cpp/types/integer
edit
If this is not C++11 (and you are getting the typedef form somewhere else (C99?)) then you can just provide the source type as a template parameter.
http://www.boost.org/doc/libs/1_40_0/libs/conversion/lexical_cast.htm#synopsis