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

std::c16rtomb cppreference.com
cppreference.com

std::c16rtomb

cppreference.com
<tbody> </tbody>
std::size_t c16rtomb( char* s, char16_t c16, std::mbstate_t* ps );
( C++11)

16- ( UTF-16) .

s , c16 16- , , ( *ps) , s, *ps . MB_CUR_MAX .

s , std::c16rtomb(buf, u'\0', ps) buf.

c16 16- , , s, *ps.

c16 u'\0', , , , *ps .

, , C.

s ,
c16 16-
ps ,

( ), , s. 0, char16_t .

( c16 16- ) -1, EILSEQ errno *ps .

C++ C . C11, std::mbrtoc16, (, UTF-8) 16- (, UTF-16), 16- , , UTF-16 UTF-8, , . C11 DR488.

. , 488 .

#include <climits>
#include <clocale>
#include <cuchar>
#include <iomanip>
#include <iostream>
#include <string_view>

int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    std::u16string_view strv = u"z"; // or z\u00df\u6c34\U0001F34C
    std::cout << " " << strv.size() << "   UTF-16: [ ";
    for (char16_t c : strv)
        std::cout << std::showbase << std::hex << static_cast<int>(c) << ' ';
    std::cout << "]\n";

    std::mbstate_t state{};
    char out[MB_LEN_MAX]{};
    for (char16_t c : strv)
    {   
        std::size_t rc = std::c16rtomb(out, c, &state);
        std::cout << static_cast<int>(c) << "   [ ";
        if (rc != (std::size_t) - 1)
            for (unsigned char c8 : std::string_view{out, rc})
                std::cout << +c8 << ' ';
        std::cout << "]\n";
    }
}

:

 5   UTF-16: [ 0x7a 0xdf 0x6c34 0xd83c 0xdf4c ]
0x7a   [ 0x7a ]
0xdf   [ 0xc3 0x9f ]
0x6c34   [ 0xe6 0xb0 0xb4 ]
0xd83c   [ ]
0xdf4c   [ 0xf0 0x9f 0x8d 0x8c ]

(C++11)
UTF-16
() []
[virtual]
internT externT, ,
:
converts a string from internT to externT, such as when writing to file
Google.
. .

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

Web Proxy Viewer  |  New URL  |  Original Page