Skip to content

Instantly share code, notes, and snippets.

@kjk
Created July 21, 2020 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjk/9532dec654e0c1bf95107e9f48daa709 to your computer and use it in GitHub Desktop.
Save kjk/9532dec654e0c1bf95107e9f48daa709 to your computer and use it in GitHub Desktop.
#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