C++ 如何在虚幻引擎中记录来自字符串变量的消息?

C++ 如何在虚幻引擎中记录来自字符串变量的消息?,c++,game-engine,unreal-engine4,C++,Game Engine,Unreal Engine4,我试图以字符串变量的形式记录消息,下面是我使用的代码 std::string s = "ss";//std::to_string(FPaths::GetPath("../")); UE_LOG(LogTemp, Warning, *s); 但它不起作用,有人能告诉我怎么做吗? 最后,我在这里回答我自己的问题 它无法编译,因为在向UE_日志中提供字符串之前,我需要使用TEXT宏 FString s = "ss"; UE_LOG(LogTemp, Warning, TEXT("%s"), *s

我试图以字符串变量的形式记录消息,下面是我使用的代码

std::string s = "ss";//std::to_string(FPaths::GetPath("../"));
 UE_LOG(LogTemp, Warning, *s);
但它不起作用,有人能告诉我怎么做吗?
最后,我在这里回答我自己的问题

它无法编译,因为在向UE_日志中提供字符串之前,我需要使用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版本的数据类型,而不是使用std库,那么您可以将std::string转换为FString,并像这样记录

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

如果答案是正确的,你可以接受自己的答案:P,并尝试使用虚幻的字符串、数组、映射等。而不是std算法,因为Unreal有它自己的魔力…只有std算法与Unreal的容器兼容,因为它们支持begin()和end(),否则我认为你应该使用Unreal的等价物。
UE_LOG(LogTemp,Warning,TEXT(“%s”),*s)