如何从 Unreal Engine 中的字符串变量记录消息?

How to log a message from a string variable in Unreal Engine?

我正在尝试从字符串变量中记录消息,下面是我使用的代码

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

但它不起作用,谁能告诉我该怎么做?

终于在这里回答我自己的问题了。

它无法编译,因为我需要在将字符串输入 UE_LOG 之前使用 TEXT 宏。

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("../"));

应该使用 Unreal 版本的 Datatypes 而不是使用标准库

如果确实需要,您可以将 std::string 转换为 FString,然后像这样记录。

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