int到* char [英] int to *char

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

问题描述



您好,


如何将int转换为* char(请最好的方式)我知道几轮

关于方法我自己:)


谢谢


Hello,

How can I convert an int to a *char (best way please) I know a few round
about methods myself :)

Thank you

推荐答案

" Nitin Manoharan" <纳米****** @ bacon.math.uwaterloo.ca>在留言中写道

新闻:Pi ************************************ @培根。 math.uwaterloo.ca ...
"Nitin Manoharan" <nm******@bacon.math.uwaterloo.ca> wrote in message
news:Pi************************************@bacon. math.uwaterloo.ca...

你好,

如何将int转换为* char(请最好的方式)我知道几轮
关于方法我自己:)

Hello,

How can I convert an int to a *char (best way please) I know a few round
about methods myself :)




您是否尝试过reinterpret_cast< char *>(an_int)或(char *)an_int?


DW



Have you tried reinterpret_cast<char*>(an_int) or (char*)an_int?

DW




" David White" < no.email@provided>在消息中写道

news:wx ****************** @ nasal.pacific.net.au ...

"David White" <no.email@provided> wrote in message
news:wx******************@nasal.pacific.net.au...
Nitin Manoharan <纳米****** @ bacon.math.uwaterloo.ca>在消息中写道
新闻:Pi ************************************ @ bacon。 math.uwaterloo.ca ...
"Nitin Manoharan" <nm******@bacon.math.uwaterloo.ca> wrote in message
news:Pi************************************@bacon. math.uwaterloo.ca...

你好,

如何将int转换为* char(请最好的方式)我知道几轮
关于方法我自己:)

Hello,

How can I convert an int to a *char (best way please) I know a few round
about methods myself :)



您是否尝试过reinterpret_cast< char *>(an_int)或(char *)an_int?

DW



Have you tried reinterpret_cast<char*>(an_int) or (char*)an_int?

DW




1.哎哟。 reinterpret_cast真的会伤害你。这就像是经历了一个

void *(事实上,我敢打赌,这就是它的实施方式)。我相信

reinterpret_cast< char *>(an_int)将为您提供由

表示的整数地址。例如:


int a = 4;

char * chr = reinterpret_cast< char *>(a);

/ * IIRC,这应该是地址0x00000004(完全无效)。* /

2.(char *)an_int,IIRC,不合法。你必须经过有效的转换:

&((char *)an_int),我认为这可以隐含于做& an_int

(自动转换为char * )



1. Ouch. reinterpret_cast can really hurt you. It''s like going through a
void* (in fact, I''ll bet that''s how it''s implemented). I believe that
reinterpret_cast<char*>(an_int) will give you the address represented by
that integer. For example:

int a = 4;
char* chr = reinterpret_cast<char*>(a);
/*IIRC, this should be the address 0x00000004 (not at all valid).*/
2. (char*)an_int, IIRC, is not legal. You must go through valid conversions:
&((char*)an_int), which I believe can be implicit by doing &an_int
(automatically converted to char*)


" MiniDisc_2k2" <马****** @ nospam.com>在消息中写道

新闻:DB ***************** @ news2.east.cox.net ...
"MiniDisc_2k2" <Ma******@nospam.com> wrote in message
news:DB*****************@news2.east.cox.net...

大卫怀特 < no.email@provided>在消息中写道
新闻:wx ****************** @ nasal.pacific.net.au ...

"David White" <no.email@provided> wrote in message
news:wx******************@nasal.pacific.net.au...
" Nitin马诺哈兰" <纳米****** @ bacon.math.uwaterloo.ca>在消息中写道
新闻:Pi ************************************ @ bacon。 math.uwaterloo.ca ...
"Nitin Manoharan" <nm******@bacon.math.uwaterloo.ca> wrote in message
news:Pi************************************@bacon. math.uwaterloo.ca...

你好,

如何将int转换为* char(请最好的方式)我知道几个
我自己围绕方法:)
您是否尝试过reinterpret_cast< char *>(an_int)或(char *)an_int?

DW

Hello,

How can I convert an int to a *char (best way please) I know a few round about methods myself :)
Have you tried reinterpret_cast<char*>(an_int) or (char*)an_int?

DW



1.哎哟。 reinterpret_cast真的会伤害你。这就像是经历了一个无效的*(事实上,我敢打赌,这就是它的实施方式)。我相信
reinterpret_cast< char *>(an_int)会给你
这个整数表示的地址。例如:

int a = 4;
char * chr = reinterpret_cast< char *>(a);
/ * IIRC,这应该是地址0x00000004(不是完全有效)。* /



1. Ouch. reinterpret_cast can really hurt you. It''s like going through a
void* (in fact, I''ll bet that''s how it''s implemented). I believe that
reinterpret_cast<char*>(an_int) will give you the address represented by
that integer. For example:

int a = 4;
char* chr = reinterpret_cast<char*>(a);
/*IIRC, this should be the address 0x00000004 (not at all valid).*/




是的,我知道它很讨厌,但如果这是OP想要做的......

2.(char *)an_int,IIRC,不合法。你必须通过有效的
转换:&((char *)an_int),我相信这可以隐含于做& an_int
(自动转换为char *)



Yes, I know it''s nasty, but if that''s what the OP wants to do...
2. (char*)an_int, IIRC, is not legal. You must go through valid conversions: &((char*)an_int), which I believe can be implicit by doing &an_int
(automatically converted to char*)




根据The D& C ++的E,reinterpret_cast用作替换旧式演员的符号

。我认为旧式演员可以做任何reinterpret_cast可以做的事情,也可能更多。


我的编译器很乐意接受(char *)an_int。


DW



According to The D & E of C++, reinterpret_cast was intended as a notation
to replace the old-style cast. I thought that old-style casts could do
anything that reinterpret_cast can do, and possibly more.

My compiler happily accepts (char*)an_int.

DW


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

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