Convert array of char[] to byte[] and vice versa? C++

前端 未结 4 848
谎友^
谎友^ 2020-12-31 07:12

What is the best way to convert an array of chars to bytes and vice versa?

Solution:

void CharToByte(char* chars, byte* bytes, unsigned int count){
          


        
4条回答
  •  悲&欢浪女
    2020-12-31 07:39

    The type char is one of the few types that has a size guaranteed by the ANSI standard and that size is 1 byte. As far as I know C does not directly define the type byte. However it would be just short of insane to have a type named byte which is not in fact a byte in size. Therefore a simple cast should do the trick.

提交回复
热议问题