I need to change the C # code below to C ++ code.
public static byte[] StrToByteArray(string str)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetBytes(str);
}
on this site I found C ++ code for UTF8Encoding from which I created this code
void StrToByteArray(string unicodeString)
{
UTF8Encoding^ utf8 = gcnew UTF8Encoding;
array<Byte>^encodedBytes = utf8->GetBytes( unicodeString );
}
but this gives me the following error:
Error 2 of error C2664: 'cli :: array ^ System :: Text :: Encoding :: GetBytes (cli :: array ^)': cannot convert parameter 1 from 'std :: string' to 'Cli :: array
Why do this while it is identical to the documentation? (except that I am using a normal string, but using a top-level string ^ gives me an error.)
I'm not sure if this is related, but my code is managed.
note: I didn’t worry about returning data until I got this working.
source
share