开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜