Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the C++ analog of C# byte[]?

What is the C++ (and or visual-C++) analog of C# byte[]?

like image 995
Rella Avatar asked Aug 22 '10 22:08

Rella


3 Answers

byte[], in C#, is an array of unsigned 8-bit integers (byte).

An equivalent would be uint8_t array[].

uint8_t is defined in stdint.h (C) and cstdint (C++), if they are not provided on your system, you could easily download them, or define them yourself (see this SO question).

like image 109
Bertrand Marron Avatar answered Sep 30 '22 18:09

Bertrand Marron


The closest equivalent type in C++ would be a dynamically created array of "unsigned char" (unless you're running on a processor that defines a byte as something other than 8 bits).

So for example

in C#

byte[] array = new byte[10];

in C++

unsigned char *array = new unsigned char[10];
like image 44
MerickOWA Avatar answered Sep 30 '22 19:09

MerickOWA


In C++ standard, char, signed char and unsigned char are three available char types. char maybe signed or unsigned, therefore:

typedef signed char sbyte;
typedef unsigned char byte;

byte bytes[] = { 0, 244, 129 };
like image 25
Sadeq Avatar answered Sep 30 '22 20:09

Sadeq