Created
July 21, 2020 08:21
-
-
Save kjk/9532dec654e0c1bf95107e9f48daa709 to your computer and use it in GitHub Desktop.
Example for https://essential-cpp.programming-books.io/user-defined-literals-d3696e4f87894401af6c2f073d356228 (made with https://codeeval.dev)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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