Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net NET中的二进制数据?(C+;+;/CLI)_.net_Managed C++ - Fatal编程技术网

.net NET中的二进制数据?(C+;+;/CLI)

.net NET中的二进制数据?(C+;+;/CLI),.net,managed-c++,.net,Managed C++,在.NET中存储二进制数据的首选方式是什么 我试过这个: byte data __gc [] = __gc new byte [100]; 得到了这个错误: error C2726: '__gc new' may only be used to create an object with managed type 有办法管理字节数组吗?CodeProject: 据我所知,“\uu gc new”语法已被弃用,请尝试以下操作: cli::array<byte>^ data = gc

在.NET中存储二进制数据的首选方式是什么

我试过这个:

byte data __gc [] = __gc new byte [100];
得到了这个错误:

error C2726: '__gc new' may only be used to create an object with managed type
有办法管理字节数组吗?

CodeProject:

据我所知,“\uu gc new”语法已被弃用,请尝试以下操作:

cli::array<byte>^ data = gcnew cli::array<byte>(100);
cli::array^data=gcnew cli::array(100);

我注意到您在cli名称空间方面有问题。阅读此文章以解决您的问题。

我不知道首选的解决方法。但是,如果您只希望对其进行编译,下面是我的机器上的C++/CLI CLRCONLE项目中的工作代码

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
    cli::array<System::Byte^>^ a = 
        gcnew cli::array<System::Byte^>(101);

    a[1] = (unsigned char)124;

    cli::array<unsigned char>^ b = 
        gcnew cli::array<unsigned char>(102);

    b[1] = (unsigned char)211;

    Console::WriteLine(a->Length);
    Console::WriteLine(b->Length);

    Console::WriteLine(a[1] + " : " + b[1]);
    return 0;
}

是托管字节的托管数组。而
b
是无符号字符的托管数组。C++似乎没有内置的代码>字节> C++ >数据类型。

你使用的是托管C++还是C++?(我可以看到Jon Skeet编辑了这个问题,将C++/CLI添加到标题中,但在我看来,您实际上使用的是托管C++)

但无论如何:

在托管C++中,你会这样做:

Byte data __gc [] = new Byte __gc [100];
cli::array<unsigned char>^ data = gcnew cli::array<unsigned char>(100);
在C++/CLI中,它如下所示:

Byte data __gc [] = new Byte __gc [100];
cli::array<unsigned char>^ data = gcnew cli::array<unsigned char>(100);
cli::array^data=gcnew cli::array(100);