How to log a message from a string variable?

What “it’s not working” means ? No log ? Crash ? Error ? Be explicit or people won’t be able to help you out :slight_smile:

Hello ,

I am trying to log a message form a string variable , below is the code I used

std::string s = "ss";//std::to_string(FPaths::GetPath("../"));
UE_LOG(LogTemp, Warning, *s);

but it’s not working, Can someone tell me how to do this ?

][1]

It does not compile

It doesn’t compile because you need to use the TEXT Macro before giving a string into UE_LOG.

FString s = "ss";
UE_LOG(LogTemp, Warning, TEXT("%s"), *s);

//or

UE_LOG(LogTemp, Warning, TEXT("ss"));

//this should work for you
UE_LOG(LogTemp, Warning, TEXT("%s"), *FPaths::GetPath("../"));

Try to work with Unreal’s version of Datatypes instead of using the std library

Greetings

Thanks friend :stuck_out_tongue:

Just for anyone else who also stumbled across this thread and crashed their editor several times, the ‘s’ in TEXT(“%s”) is in no way related to the name of the FString variable, which is also ‘s’. That’s just very poor design of the example above. Here’s a more helpful example.

FString Message = "Important Message!!!";
UE_LOG(LogTemp, Warning, TEXT("%s"), *Message);

Even though this thread is 6 years old, it’s still the top google result, so I thought it would be worth addressing.

5 Likes