[英]Convert from char to byte
Hello is there a way that makes you convert from char to byte.您好,有没有一种方法可以让您从字符转换为字节。 I know that in c# there is the Method.
我知道在 c# 中有方法。
Convert.ToByte('a');
But what is it in c++?但它在 C++ 中是什么? I have tryed google it but i cant find any answer.
我试过谷歌它,但我找不到任何答案。
Unlike C#, C++ does not have a built-in data type named byte
.与 C# 不同,C++ 没有名为
byte
的内置数据类型。 In addition, its char
type has a size of one byte, as opposed to C#, which uses 16-bit characters, so the conversion is always trivial.此外,它的
char
类型的大小为 1 个字节,而 C# 使用 16 位字符,因此转换总是微不足道的。
If you want your code to be explicit about the sign of your eight-bit data type, use <cstdint>
header, declare a variable of type uint8_t
, and assign the character to it:如果您希望代码明确八位数据类型的符号,请使用
<cstdint>
标头,声明一个uint8_t
类型的变量,并将字符分配给它:
uint8_t x = 'a';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.