< cpp‎ | string‎ | wide
Revision as of 13:42, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

Defined in header <cwchar>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
std::size_t strxfrm( const wchar_t* dest, const wchar_t* src, std::size_t count );

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Transforms the null-terminated wide string pointed to by src into the implementation-defined form such that comparing two transformed strings with std::wcscmp gives the same result as comparing the original strings with std::wcscoll, in the current C locale.

The first count characters of the transformed string are written to destination, including the terminating null character, and the length of the full transformed string is returned, excluding the terminating null character.

If count is 0, then dest is allowed to be a null pointer.



The correct length of the buffer that can receive the entire transformed string is 1+std::wcsxfrm(NULL, src, 0)


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

Return value

The length of the transformed wide string, not including the terminating null-character.


#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';
         std::wcout << in2 << " before " << in1 << '\n';
    std::wcout << "In lexicographical comparison: ";
    if(in1 < in2)
         std::wcout << in1 << " before " << in2 << '\n';
         std::wcout << in2 << " before " << in1 << '\n';


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

See also

Template:cpp/string/byte/dcl list strxfrmTemplate:cpp/locale/collate/dcl list do transformTemplate:cpp/string/wide/dcl list wcscoll
C documentation for wcsxfrm