[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/string/multibyte/wctomb [Back]  [Original]

std::wctomb cppreference.com
cppreference.com

std::wctomb

cppreference.com
<tbody> </tbody>
int wctomb( char *s, wchar_t wc );

wc ( ) , s. MB_CUR_MAX . LC_CTYPE .

wc , s, , .

s , , .

s
wc

s , , wc -1, wc .

s , , , 0, ( ) , ( ).

wctomb ( std::mbstate_t, ). , . wctomb : std::wcrtomb.

#include <iostream>
#include <iomanip>
#include <clocale>
#include <string>
#include <cstdlib>

void print_wide(const std::wstring& wstr)
{
    bool shifts = std::wctomb(nullptr, 0); //   
    std::cout << "  " << (shifts ? "" : "" )
              << " \n" << std::uppercase << std::setfill('0');
    for (const wchar_t wc : wstr)
    {
        std::string mb(MB_CUR_MAX, '\0');
        const int ret = std::wctomb(&mb[0], wc);
        const char* s = ret > 1 ? "s" : "";
        std::cout << "  '" << mb << "'  " << ret
                  << " " << s << ": [" << std::hex;
        for (int i{0}; i != ret; ++i)
        {
            const int c = 0xFF & mb[i];
            std::cout << (i ? " " : "") << std::setw(2) << c;
        }
        std::cout << "]\n" << std::dec;
    }
}

int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    //    UTF-8
    std::wstring wstr = L"z\u00df\u6c34\U0001d10b"; //  L"z"
    print_wide(wstr);
}

:

   
  'z'  1 : [7A]
  ''  2 : [C3 9F]
  ''  3 : [E6 B0 B4]
  ''  4 : [F0 9D 84 8B]


() []

() []
[virtual]
internT externT, ,
:
converts a string from internT to externT, such as when writing to file
Google.
. .

(virtual protected std::codecvt -) []
C wctomb

Web Proxy Viewer  |  New URL  |  Original Page