16

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 ? enter image description here

2 Answers 2

35

Finally I am answering my own question here.

It doesn't compile because I 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
 UE_LOG(LogTemp, Warning, TEXT("%s"), *FPaths::GetPath("../"));

should work with Unreal's version of Datatypes instead of using the std library

Sign up to request clarification or add additional context in comments.

3 Comments

You can accept your own answer if it's correct :P And try to use Unreal's string, array, map...etc. instead of std ones since Unreal has its own magic...
Only the std algorithms are compatible with Unreal's containers since they support begin() and end(), otherwise I think you should use Unreal's equivalents.
UE_LOG(LogTemp, Warning, TEXT("%s"), *s); 🤦
6

If you really have to than you can convert std::string to FString and than log that like this.

std::string someString = "Hello!";
FString layerName(someString .c_str());
UE_LOG(LogTemp, Warning, TEXT("%s"), *layerName);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.