什么是C#byte []的C++模拟?

Rel*_*lla 8 c# c++ byte bytearray visual-c++

什么是C#的C++(和Visual C++)模拟byte[]

Ber*_*ron 12

byte[]在C#中,是一个无符号8位整数数组(byte).

相当于uint8_t array[].

uint8_t在stdint.h(C)和cstdint(C++)中定义,如果你的系统没有提供它们,你可以轻松下载它们,或者自己定义它们(参见这个问题).

  • 或者更常规地,`unsigned char` (3认同)
  • @theatrus,不,`char`不保证是8位类型. (3认同)
  • @praetorian:CHAR_BITS> = 8.所以char不能小于8但它可以更大.uint8_t只需要支持8位操作.但谁说编译器需要在char上建模uint8_t.http://linux.die.net/man/3/uint8_t (2认同)
  • @Praetorian:在这个平台上,它被定义为char,因为它适用于这个平台.但是没有标准要求(我怀疑)它必须是一个char(只需要它是8位).这是另一种说出金缕梅说的话. (2认同)

M. *_* E. 6

在C++标准中char,signed charunsigned char三种可用的char类型.char或许,signedunsigned因此:

typedef signed char sbyte;
typedef unsigned char byte;

byte bytes[] = { 0, 244, 129 };
Run Code Online (Sandbox Code Playgroud)


Mer*_*OWA 5

C ++中最接近的等效类型是动态创建的“无符号字符”数组(除非您在将字节定义为8位以外的值的处理器上运行)。

所以举个例子

在C#中

byte[] array = new byte[10];
Run Code Online (Sandbox Code Playgroud)

在C ++中

unsigned char *array = new unsigned char[10];
Run Code Online (Sandbox Code Playgroud)

  • 您不是在说`byte [] array = new byte [10]`吗? (2认同)