2013-04-18 1435 views
0

如何在C++中声明byte *(byte array)以及如何在函数定义中将其定义为参数?如何在C++中声明byte *(byte array)?

当我宣布类似下面

函数声明

int Analysis(byte* InputImage,int nHeight,int nWidth); 

收到错误: “字节” 未定义

+0

使用无符号的字符来代替。它相同....一个字节 –

+0

那么我应该如何转换字节*中的无符号字符,从C#应用程序获取字节数组输入。 – Pixel

+0

你想从C#中的字节转换为字符在C + +?我的理解是否正确? –

回答

3

没有类型byte在C++中。您应该先使用typedef。像

typedef std::uint8_t byte; 
在C++ 11

,或者

typedef unsigned char byte; 

在C++ 03。

2

代表一个字节的C++类型是unsigned char(或其他符号风格char,但是如果你想要它作为普通字节,unsigned可能就是你以后的样子)。

但是,在现代C++中,您不应该使用原始数组。如果阵列是运行时大小,则使用std::vector<unsigned char>;如果阵列的大小为N,则使用std::array<unsigned char, N>(C++ 11)。您可以通过(常量)引用通过这些来的功能,像这样:

int Analysis(std::vector<unsigned char> &InputImage, int nHeight, int nWidth); 

如果Analysis不修改数组或它的元素,这样做,而不是:

int Analysis(const std::vector<unsigned char> &InputImage, int nHeight, int nWidth);