C++ cli 转换本机字节。。。? < >我如何将一个本地字节(unChar char)类型变量转换为一个托管字节数组,数组是C++中的数组^?p> byte sData[255]; // convert to System::Byte array or copy content to byteArray?? How? array<System::Byte>^ byteArray; 字节数据[255];//转换为System::Byte数组或将内容复制到byteArray??怎么用? 数组^byteArray;

C++ cli 转换本机字节。。。? < >我如何将一个本地字节(unChar char)类型变量转换为一个托管字节数组,数组是C++中的数组^?p> byte sData[255]; // convert to System::Byte array or copy content to byteArray?? How? array<System::Byte>^ byteArray; 字节数据[255];//转换为System::Byte数组或将内容复制到byteArray??怎么用? 数组^byteArray;,c++-cli,C++ Cli,谢谢你的帮助 您可以这样做: char buf[] = "Native String"; int len = strlen(buf); array<Byte> ^byteArray = gcnew array<Byte>(len + 2); Marshal::Copy( (IntPtr)buf, byteArray, 0, len ); charbuf[]=“本机字符串”; int len=strlen(buf); 数组^byteArray=gcnew数组(len+2)

谢谢你的帮助

您可以这样做:

char buf[] = "Native String";
int len = strlen(buf);
array<Byte> ^byteArray = gcnew array<Byte>(len + 2);
Marshal::Copy( (IntPtr)buf, byteArray, 0, len );
charbuf[]=“本机字符串”;
int len=strlen(buf);
数组^byteArray=gcnew数组(len+2);
封送:复制((IntPtr)buf,byteArray,0,len);
您可以在MSDN文章中找到更多信息。

int size=Mat.total()*Mat.elemSize();
int size = Mat.total() * Mat.elemSize();
byte * bytes = new byte[size];
std::memcpy(bytes, Mat.data, size * sizeof(byte));

// convert native byte array to managed Byte array
array<Byte> ^byteArray = gcnew array<Byte>(size + 2);
Marshal::Copy((IntPtr)bytes, byteArray, 0, size);
字节*字节=新字节[大小]; std::memcpy(字节,Mat.data,size*sizeof(字节)); //将本机字节数组转换为托管字节数组 数组^byteArray=gcnew数组(大小+2); 封送:复制((IntPtr)字节,字节数组,0,大小);
这不是,它是或什么的。Thx伙计……我来试试