This is not the way you are supposed to handle text in Unreal!
You are giving the control over to the compiler to decide what exactly do you mean by u"虚幻四真好用" in bytes. Unreal uses a custom compiler which means that some things are bound to be different than the normal Visual Studio.
I strongly suggest you use the built-in data types in unreal like FString and FText to deal with strings.
UE4 uses “wchar_t” by default to handle strings, which is different from compiler-generated UTF-16 strings (what you are trying to do) because they use “char16_t”. “wchar_t” has a different size depending on the platform (typically 2 bytes on Windows and 4 bytes on Unix-based systems), whereas "char16_t’ is always 2 bytes per character.
Instead of saying u"虚幻四真好用", you need to say TEXT(“虚幻四真好用”).
The implement of TEXT() is to add a prefix ‘L’ to the string, which in most case works the same as prefix ‘u’ in windows.
In fact, TEXT() still do not work correctly. The value in FString is not the same as the string literal.
You can test this on your own, and do not forget to change the encoding format of the .cpp file to gbk.
But prefix ‘u’ is one of the c++ standard, which makes sure that the value of the string is in utf16.
If ue4’s compiler does not support this standard, it should tag that as an error.
This cause a lot of trouble in building the three-part library in ue4.
By the way, FString does not work correctly, too. The only solution is to change the code file to utf8.
It seems that the encoding format of the string is depending on the encoding format of the code file.
Unreal documentation has a whole section dedicated to using strings.
If you go out of your way to intentionally circumvent the engine, it’s memory management (with std::memcpy()) and data types (unit16_t and char16_t) it should no longer be held responsible for the outcome.
No error is tagged because no error has occurred. You copy some memory from one place to the other. The compiler does not care if you have taken the right memory or you interpret it in the right way. This is up to you.