how to convert long value to string without changing its content?
hi a have a pointer variable with value 0x6859510364 , i have to convert it in to string wihtout changing its value. please can anyon开发者_如何学Goe help me. thanks in advance.
you can always use a std::ostringstream
, like
#include <sstream>
#include <string>
std::string toString( void* p )
{
std::ostringstream stream;
stream << p;
return stream.str();
}
note: if it is a function pointer then it's not formally convertible to void*
, and then you have to adjust signature of function above to take your pointer type.
you may also have to add const
etc.
instead of writing such functions yourself you can use boost::lexical_cast
, from the Boost library.
Cheers & hth.,
long* number;//=0x6859510364;
TCHAR str[20];
_ltot_s(*number, str, 16);
精彩评论