如何将字节转换为char [英] how to cast byte to char

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

问题描述

如何更改字节变量以便我可以将其字符值添加到

字符串类型变量的末尾,这样:


String ^ s =" 1234";

byte b;

b = 53;


s = s + b;


因此s =" 12345"。


我无法使用演员。


s = s +(char)b;


不起作用。


Daniel

解决方案

Daniel写道:


如何更改字节变量以便我可以添加它''字符值为

字符串类型变量的结尾,例如:


String ^ s =" 1234";

字节b;

b = 53;


s = s + b;


因此s =" 12345。


我无法使用演员。


s = s +(char)b;


无效。



Daniel:


1.如果您考虑使用标准C ++,那将是件好事。 >
或C ++ / CLI(两种*不同的*语言),并相应地发布。


2.如果您描述不起作用,那也会很好。 。你有什么期望?b $ b期待什么,发生了什么?代码编译失败了吗?还是链接?还是跑?或者

给出你期望的结果?


-

David Wilkinson

Visual C ++ MVP


" Daniel" < ne ****** @ cableone.netwrote in message

news:OC ************** @ TK2MSFTNGP02.phx.gbl ...


如何更改字节变量以便我可以将它的字符值添加到

字符串类型变量的末尾,这样:


String ^ s =" 1234" ;;



c ++没有类型字符串。没有定义,类型,结构或类

语法错误。 ^是语法错误。那不是C ++


byte b;



c ++没有类型字节。没有typedef或结构或类定义

这是一个语法错误。那不是C ++


b = 53;


s = s + b;


因此s =" 12345"。


我无法使用演员。


s = s +(char )b;


不起作用。



当然它不起作用,这不是合法的C ++代码。如果你想询问

关于其他语言,请在新闻组中发布关于其他

语言的内容。


谢谢。

-

Jim Langston


在我给出的例子中,s = s + b导致秒。 b没有得到

连接。至于标准C ++或C ++ / CLI,我无法区分它们。

我不是很精通技术能够告诉你。


Daniel


" David Wilkinson" < no ****** @ effisols.com写信息

新闻:eL ************* @ TK2MSFTNGP06.phx.gbl ...


Daniel写道:


>如何更改字节变量以便我可以添加它''字符值为
字符串类型变量的结尾,例如:

字符串^ s =" 1234" ;;
字节b;
b = 53;

s = s + b;

因此s =" 12345"。

我无法使用演员阵容。

s = s +(char)b;

不起作用。



丹尼尔:


1.如果你考虑是否使用标准将会很好

C ++或C ++ / CLI(两种*不同的*语言),并据此发布。


2.如果你描述了什么不起作用也会很好。 。

你期待什么,发生了什么?代码编译失败了吗?还是链接?或者

运行?或者给出你期望的结果?


-

David Wilkinson

Visual C ++ MVP



How do I change a byte variable so that I can add it''s character value to
the end of a variable of type string, such that:

String^ s = "1234";
byte b;
b= 53;

s = s + b;

thus s = "12345".

I wasn''t able to use a cast.

s = s + (char)b;

did not work.

Daniel

解决方案

Daniel wrote:

How do I change a byte variable so that I can add it''s character value to
the end of a variable of type string, such that:

String^ s = "1234";
byte b;
b= 53;

s = s + b;

thus s = "12345".

I wasn''t able to use a cast.

s = s + (char)b;

did not work.

Daniel:

1. It would be good if you were to consider whether you are using standard C++
or C++/CLI (two *different* languages), and post accordingly.

2. It would also be good if you described what "did not work". What did you
expect, and what happened? Did the code fail to compile? Or link? Or run? Or to
give the result you expected?

--
David Wilkinson
Visual C++ MVP


"Daniel" <ne******@cableone.netwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...

How do I change a byte variable so that I can add it''s character value to
the end of a variable of type string, such that:

String^ s = "1234";

c++ has no type String. Without a definition, type, struct or class that is
a syntax error. ^ is a syntax error. That is not C++

byte b;

c++ has no type byte. Without a typedef or structure or class definition
that is a syntax error. That is not C++

b= 53;

s = s + b;

thus s = "12345".

I wasn''t able to use a cast.

s = s + (char)b;

did not work.

Of course it didn''t work, that''s not legal C++ code. If you mean to ask
about some other language, please post in a newsgroup about that other
language.

Thank you.
--
Jim Langston


In the example that I gave, s=s+b resulted in s. The b did not get
concatenated. As for standard C++ or C++/CLI, I can''t tell the difference.
I''m not that well versed in the technology to be able to tell you.

Daniel

"David Wilkinson" <no******@effisols.comwrote in message
news:eL*************@TK2MSFTNGP06.phx.gbl...

Daniel wrote:

>How do I change a byte variable so that I can add it''s character value to
the end of a variable of type string, such that:

String^ s = "1234";
byte b;
b= 53;

s = s + b;

thus s = "12345".

I wasn''t able to use a cast.

s = s + (char)b;

did not work.


Daniel:

1. It would be good if you were to consider whether you are using standard
C++ or C++/CLI (two *different* languages), and post accordingly.

2. It would also be good if you described what "did not work". What did
you expect, and what happened? Did the code fail to compile? Or link? Or
run? Or to give the result you expected?

--
David Wilkinson
Visual C++ MVP



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

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