Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要一个返回字符的 UNICODE 值的函数。 在 java String.valueOf('а'); 已验证。c++中是否有等效功能?
这个问题在 C++ 的上下文中真的没有意义。您必须定义 Unicode 值(哪种编码格式)的含义——Java 坚持使用 UTF-16,但可以说 UTF-8 或 UTF-32 更有意义。
此外,尽管有名称,Java 函数不会更改或重新解释任何值。它与 C++ 中的完全等价wstring( 1, L'a' ),至少在wchar_tUTF-16 的机器上是这样。(在 C++11 中,您可以强制使用 UTF-16,使用 std::u16string( 1, u'a' ).)
wstring( 1, L'a' )
wchar_t
std::u16string( 1, u'a' )