Comment : convertir la chaîne char * en tableau System::Byte
La méthode la plus efficace pour convertir une char *
chaîne en tableau Byte consiste à utiliser Marshal la classe.
Exemple
// convert_native_string_to_Byte_array.cpp
// compile with: /clr
#include <string.h>
using namespace System;
using namespace System::Runtime::InteropServices;
int main() {
char buf[] = "Native String";
int len = strlen(buf);
array< Byte >^ byteArray = gcnew array< Byte >(len + 2);
// convert native pointer to System::IntPtr with C-Style cast
Marshal::Copy((IntPtr)buf,byteArray, 0, len);
for ( int i = byteArray->GetLowerBound(0); i <= byteArray->GetUpperBound(0); i++ ) {
char dc = *(Byte^) byteArray->GetValue(i);
Console::Write((Char)dc);
}
Console::WriteLine();
}
Native String
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour