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:
- 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:
- https://answers.unrealengine.com/que…haracters.html
- https://forums.unrealengine.com/deve…-to-std-string
- https://docs.unrealengine.com/en-US/…ing/index.html
- and which let me think a bit more about this subject: https://www.joelonsoftware.com/2003/…ts-no-excuses/
- to avoid dealing with unsecure temporarely objects we can use
StringCast<ANSICHAR>(*FSTRINGVARIABLE).Get()
to convert a Fstring to a char*
- this means the above approach would be
char* result = StringCast<ANSICHAR>(*myFString).Get();