Convert std::string to FString

char*

Hi Rama (and everybody)!

I must admit I’ve been lurking in the forums for quite some time now, but I never dared to post. Now, however I have a matter that needs solving:

What if I need to convert to char* ? I’m currently doing this, but it doesn’t strike me as nice code:


FString hlString = "Whatever";
std::string mlString(TCHAR_TO_UTF8(*hlString));
char* llString = &mlString[0];

Somehow the back of my brain tingles saying “memory management” with the last line, but this is the best approximation of what I want based on multiple StackOverflow answers (except maybe the vector approach, but I do need a raw char*). Is there any way I could improve this? Also, is it okay to use TCHAR_TO_ANSI if I can guarantee only ANSI chars will be used? Is there any benefit in doing so?

As far as I can imagine, the inverse case is much safer, considering I’ve already managed the char*, isn’t it?


char* llString = "Something";
std::string mlString(llString);
FString hlString(FString(mlString.c_str()));

P.S.: Thanks for EVERYTHING you post, it’s a source of inspiration and it is always helpful.