can the type of "FString" be converted to "char*" in ue4 c++?

Although this is a very old thread, but i stumbled over the problem that i needed a const char* from an FString for a function call. And this approach didn´t work for me and i digged deeper and found some good sources which might be interesting if you stumble over this post:

  1. TCHAR_TO_ANSI(…) and other Encoding Macros need be used carefully because the result is a pointer to a temporary object and


char* result = TCHAR_TO_ANSI(*myFString);

is a bad idea. These Macro-calls only should be used when they are used as a function parameter.

The sources:

  1. to avoid dealing with unsecure temporarely objects we can use

StringCast<ANSICHAR>(*FSTRINGVARIABLE).Get()

to convert a Fstring to a char*

  1. this means the above approach would be

char* result = StringCast<ANSICHAR>(*myFString).Get();

7 Likes