Skip to content

Instantly share code, notes, and snippets.

@kjk
Created Jul 21, 2020
Embed
What would you like to do?
#include <codecvt>
#include <iostream>
#include <locale>
#include <string>
int main()
{
using namespace std::literals::string_literals;
std::string s = "hello world"s;
std::u16string s16 = u"hello world"s;
std::u32string s32 = U"hello world"s;
std::wstring ws = L"hello world"s;
std::cout << s << std::endl;
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
std::cout << utf16conv.to_bytes(s16) << std::endl;
std::wstring_convert<std::codecvt_utf8_utf16<char32_t>, char32_t> utf32conv;
std::cout << utf32conv.to_bytes(s32) << std::endl;
std::wcout << ws << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment