在线文档教程
C++
字符串 | Strings

std::wcsxfrm

STD::wcsxfrm

Defined in header
std::size_t strxfrm( wchar_t* dest, const wchar_t* src, std::size_t count

转换以空结尾的宽字符串。src转换为实现定义的形式,以便将两个转换后的字符串与std::wcscmp提供的结果与将原始字符串与std::wcscoll,在当前的C语言环境中。

第一count将转换字符串的字符写入目标,包括终止空字符,并返回完全转换字符串的长度,不包括终止空字符。

如果count​0​,然后dest允许为空指针。

注记

可以接收整个转换字符串的缓冲区的正确长度是1+std::wcsxfrm(NULL, src, 0)...

此函数用于使用相同的宽字符串或宽字符串集进行多个依赖于区域设置的比较,因为使用它更有效。std::wcsxfrm将所有字符串只转换一次,然后将转换后的宽字符串与std::wcscmp...

参数

dest-pointer to the first element of a wide null-terminated string to write the transformed string to
src-pointer to the null-terminated wide character string to transform
count-maximum number of characters to output

返回值

转换后的宽字符串的长度,不包括终止空字符.

二次

#include <iostream> #include <cwchar> int main() { std::setlocale(LC_ALL, "sv_SE.utf8" std::wstring in1 = L"\u00e5r"; std::wstring out1(1+std::wcsxfrm(nullptr, in1.c_str(), 0), L' ' std::wstring in2 = L"\u00e4ngel"; std::wstring out2(1+std::wcsxfrm(nullptr, in2.c_str(), 0), L' ' std::wcsxfrm(&out1[0], in1.c_str(), out1.size() std::wcsxfrm(&out2[0], in2.c_str(), out2.size() std::wcout << "In the Swedish locale: "; if(out1 < out2) std::wcout << in1 << " before " << in2 << '\n'; else std::wcout << in2 << " before " << in1 << '\n'; std::wcout << "In lexicographical comparison: "; if(in1 < in2) std::wcout << in1 << " before " << in2 << '\n'; else std::wcout << in2 << " before " << in1 << '\n'; }

二次

产出:

二次

In the Swedish locale: år before ängel In lexicographical comparison: ängel before år

二次

另见

strxfrmtransform a string so that strcmp would produce the same result as strcoll (function)
do_transform virtualtransforms a string so that collation can be replaced by comparison (virtual protected member function of std::collate)
wcscollcompares two wide strings in accordance to the current locale (function)

c Wcsxfrm文档

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/string/Wide/wcsxfrm