使用虚幻引擎4,我想从机器加载一个文件,其中包含“、”、‘和’等字符。
所有转换尝试都会产生包含?的最终FString,或者根本不包含任何字符。
FString是ue4的内部字符串类,它使用TCHAR (wchar_t),后者使用UTF-16编码。
即使是孤注一掷的尝试也失败了:
std::replace(str.begin(), str.end(), L'“', L'\"');什么都没发生。
如何正确地将std::string转换为FString
发布于 2018-06-25 16:05:38
将您的std::string转换为std::wstring,因为它也是在wchar_t上模板化的,并尝试用它初始化FString。
如果您不知道如何转换为wstring:c++ can't convert string to wstring,请查看此主题
然后你可以这样做:
FString str = FString(your_wstring.c_str());或
FString str(your_wstring.c_str());
您还可以尝试将数据从文件直接读取到wstring甚至FString,因为UE4有自己的用于管理文件的类,例如FFileHelper:http://api.unrealengine.com/INT/API/Runtime/Core/Misc/FFileHelper/index.html,我真的建议您使用最后一个选项:-)
发布于 2019-11-12 23:13:26
您可以将std::string转换为FString,然后像这样记录。
std::string someString = "Hello!";
FString unrealString(someString .c_str());
UE_LOG(LogTemp, Warning, TEXT("%s"), *unrealString);然后,您可以对其执行FString替换功能。https://docs.unrealengine.com/en-US/API/Runtime/Core/Containers/FString/Replace/index.html
https://stackoverflow.com/questions/50843234
复制相似问题