How do you convert FString into Char* ?


    const char* bufmessage = PlayerLocation;
    int sendOK = sendto(out, bufmessage, strlen(bufmessage), 0, (sockaddr*)&server, sizeof(server));

no suitable conversion for FString to const char*

Try:


const TChar* message = *PlayerLocation.ToString();

Remember that a TChar can be 8/ 16 or 32bit depending on the platform. It can be either a wchar_t (8, 16, 32bit) or a char16.

There are flags that you can check to determine which size a character has and what TChar actually responds to. Using these flags in #if blocks let you adapt to various different platforms. Also remember endianess plays a role since some platforms are little and other big endian.
Some examples of these flags: PLATFORM_TCHAR_IS_CHAR16, PLATFORM_TCHAR_IS_1_BYTE, PLATFORM_TCHAR_IS_2_BYTE, PLATFORM_TCHAR_IS_4_BYTE.

Honest advise use build in functionality to convert TChar arrays to something standard like TCHAR_TO_UTF8(str) and UTF8_TO_TCHAR(str) for converting your characters to UTF8 and back. There are other versions for UTF16, ANSI etc.

WS2tcpip converts the message to the correct endiness (probably).

Should I be posting my windows version with this? not sure if that would determine which TCHAR is used.

I’m getting stuck on a ton of issues now. Figuring out what the TCHAR is, which format and how to use them. When to use pointers is a mystery… I just kind of guess and check right now. The UE4 docs are a killer. Very sparse, no examples, and sometime don’t have the includes (like CharacterEncoding). The wiki and this forum post made the solution possible but it took me a while to figure out I needed the legacy wiki. https://www.ue4community.wiki/Legacy…oat_to_FString

It just sucks trying to give this project a proper attempt but there is almost no help out there. 90% of the time a google search brings back blueprints, chinese, or the incorrect conversion. Thanks to the 90,000 people who had to ask instead of googling string to fstring.


    FVector MyCharacter = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
    FString CharVector = MyCharacter.ToString();
    std::string VectorString(TCHAR_TO_UTF8(*CharVector));
    const char* message = VectorString.c_str();
    WriteToSocket(message);

full code that is sending the vector information to the server

Thank you, probably should of lead with that lol