将unsigned char *转换为const char * [英] Converting a unsigned char * to const char *

查看:863
本文介绍了将unsigned char *转换为const char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能吗?很抱歉,如果这个问题与此无关。


实际上,我正在尝试将无符号字符*转换为int

解决方案

" hamishd" < Ha ********* @ gmail.comwrote in message

news:11 ********************* *@x35g2000prf.googlegr oups.com ...


这可能吗?很抱歉,如果这个问题与此无关。


实际上,我正在尝试将无符号字符*转换为int



您是否尝试转换指针的值,或指针指向的指针是什么?


无论如何,reinterpret_cast是你想要什么。

reinterpret_cast< int>(Foo);


在2007-08-04 11:47,Jim Langston写道:


" hamishd" < Ha ********* @ gmail.comwrote in message

news:11 ********************* *@x35g2000prf.googlegr oups.com ...


>这可能吗?很抱歉,如果这个问题与此无关。

实际上,我正在尝试将无符号字符*转换为int



你试图转换指针的值,或指针指向的指针是什么?


无论哪种方式,reinterpret_cast都是你想要的。

reinterpret_cast< int>(Foo);



reinterpret_cast不需要它是一个未签名的char -int

转换OP试图做的,两者都是整数类型所以正常的

作业应该这样做吧?


-

Erik Wikstr?m


Jim Langston写道:


" hamishd" < Ha ********* @ gmail.comwrote in message

news:11 ********************* *@x35g2000prf.googlegr oups.com ...


>这可能吗?很抱歉,如果这个问题与此无关。

实际上,我正在尝试将无符号字符*转换为int



你试图转换指针的值,或指针指向的指针是什么?


无论哪种方式,reinterpret_cast都是你想要的。

reinterpret_cast< int>(Foo);



我认为reinpterpret_cast确实*不*与constness一起工作

也许static_cast和const_cast一起工作


Is this possible? Sorry if this question isn''t relevant here.

actually, I''m really trying to convert a unsigned char * to an int

解决方案

"hamishd" <Ha*********@gmail.comwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...

Is this possible? Sorry if this question isn''t relevant here.

actually, I''m really trying to convert a unsigned char * to an int

Are you trying to convert the value of the pointer, or where the pointer is
pointing to?

Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );


On 2007-08-04 11:47, Jim Langston wrote:

"hamishd" <Ha*********@gmail.comwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...

>Is this possible? Sorry if this question isn''t relevant here.

actually, I''m really trying to convert a unsigned char * to an int


Are you trying to convert the value of the pointer, or where the pointer is
pointing to?

Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );

reinterpret_cast should not be needed it it''s a unsigned char -int
conversion the OP is trying to do, both are integer types so a normal
assignment should do, right?

--
Erik Wikstr?m


Jim Langston wrote:

"hamishd" <Ha*********@gmail.comwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...

>Is this possible? Sorry if this question isn''t relevant here.

actually, I''m really trying to convert a unsigned char * to an int


Are you trying to convert the value of the pointer, or where the pointer is
pointing to?

Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );

I think reinpterpret_cast does *NOT* work with constness
maybe static_cast and const_cast together will work


这篇关于将unsigned char *转换为const char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆