Reputation: 43
Hello is there a way that makes you convert from char to byte. I know that in c# there is the Method.
Convert.ToByte('a');
But what is it in c++? I have tryed google it but i cant find any answer.
Upvotes: 2
Views: 10683
Reputation: 726519
Unlike C#, C++ does not have a built-in data type named 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.
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:
uint8_t x = 'a';
Upvotes: 3