how to encode utf 8 cpp

Solutions on MaxInterview for how to encode utf 8 cpp by the best coders in the world

showing results for - "how to encode utf 8 cpp"
Tim
25 Nov 2017
1#include <iostream>
2#include <string>
3#include <locale>
4#include <codecvt>
5 
6int main()
7{
8    // UTF-8 data. The character U+1d10b, musical sign segno, does not fit in UCS2
9    std::string utf8 = u8"z\u6c34\U0001d10b";
10 
11    // the UTF-8 / UTF-16 standard conversion facet
12    std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
13    std::u16string utf16 = utf16conv.from_bytes(utf8);
14    std::cout << "UTF16 conversion produced " << utf16.size() << " code units:\n";
15    for (char16_t c : utf16)
16        std::cout << std::hex << std::showbase << c << '\n';
17
18}
similar questions
queries leading to this page
how to encode utf 8 cpp