Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.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
C++ cli 转换数组的正确方法<;无符号字符>;^到std::string_C++ Cli - Fatal编程技术网

C++ cli 转换数组的正确方法<;无符号字符>;^到std::string

C++ cli 转换数组的正确方法<;无符号字符>;^到std::string,c++-cli,C++ Cli,我想知道将托管数组^转换为非托管std::string的正确方法是什么。我现在做的是: array<unsigned char>^ const content = GetArray(); auto enc = System::Text::Encoding::ASCII; auto const source = enc->GetString(content); std::string s = msclr::interop::marshal_as<std::string>

我想知道将托管
数组^
转换为非托管
std::string
的正确方法是什么。我现在做的是:

array<unsigned char>^ const content = GetArray();
auto enc = System::Text::Encoding::ASCII;
auto const source = enc->GetString(content);
std::string s = msclr::interop::marshal_as<std::string>(source);
但这给了我以下错误:

Error   C4996   'msclr::interop::error_reporting_helper<_To_Type,cli::array<unsigned char,1> ^,false>::marshal_as': 
This conversion is not supported by the library or the header file needed for this conversion is not included.  
Please refer to the documentation on 'How to: Extend the Marshaling Library' for adding your own marshaling method.

Error   C2065   '_This_conversion_is_not_supported': undeclared identifier  
错误C4996'msclr::interop::Error_reporting_helper::marshal_as':
库不支持此转换,或者不包括此转换所需的头文件。
请参阅有关“如何:扩展封送处理库”的文档,以添加您自己的封送处理方法。
错误C2065“\u此\u转换\u不受支持”:未声明的标识符

如果数组是纯字节,那么它已经是ASCII编码的(或者您正在使用的任何窄字符)。转换为托管UTF-16
String^
是不必要的迂回

只需从字节数组构造一个窄字符串。传递指向第一个字节和长度的指针

array<unsigned char>^ const content = GetArray();
pin_ptr<unsigned char> contentPtr = &content[0];
std::string s(contentPtr, content->Length);
array^const content=GetArray();
pinptr contentPtr=&content[0];
std::字符串s(contentPtr,content->Length);

我现在不在编译器旁,可能会有一些小的语法错误。

如果数组是纯字节,那么它已经是ASCII编码的(或者您正在使用的任何窄字符)。转换为托管UTF-16
String^
是不必要的迂回

只需从字节数组构造一个窄字符串。传递指向第一个字节和长度的指针

array<unsigned char>^ const content = GetArray();
pin_ptr<unsigned char> contentPtr = &content[0];
std::string s(contentPtr, content->Length);
array^const content=GetArray();
pinptr contentPtr=&content[0];
std::字符串s(contentPtr,content->Length);
我现在不在编译器那里,可能有一些小的语法错误