C++ builder - convert UnicodeString to UTF-8 encoded string
c++builder, utf-8
Solution
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
char dest[256]; // room for 256 characters
UnicodeString src = L"Test this";
UnicodeToUtf8( dest, 256, src, src.Length() );
But in reality you can use the easier:
char dest[256]; // room for 256 characters
UnicodeString src = L"Test this";
UnicodeToUtf8( dest, src, 256 );
Problem
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?