I try to convert UnicodeString to UTF-8 encoded string in C++ builder. I use UnicodeToUtf8() function to do that.
char * dest;
UnicodeSring src;
UnicodeToUtf8(dest,256,src.w_str(),src.Length());
but compiler shows me runtime access violation message. What I’m doing wrong?
This fixes the problem in the question, but the real way to do a UTF16 to UTF8 conversion is in Remy’s answer below.
dest is a pointer to a random space in memory because you do not initialize it. In debug builds it probably points to 0 but in release builds it could be anywhere. You are telling UnicodeToUtf8 that dest is a buffer with room for 256 characters.
Try this
But in reality you can use the easier: