Skip to content

Instantly share code, notes, and snippets.

@remyroez
Created October 25, 2016 07:05
Show Gist options
  • Save remyroez/8c4d38c805141db6b35b82b041511c80 to your computer and use it in GitHub Desktop.
Save remyroez/8c4d38c805141db6b35b82b041511c80 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
int main()
{
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
std::string u8str = u8"abcdeあいうえお🗿";
std::u32string u32str = converter.from_bytes(u8str);
std::cout << "u8str = " << u8str << std::endl;
std::cout << "u8str.length = " << u8str.length() << std::endl;
std::cout << "u32str.length = " << u32str.length() << std::endl;
std::cout << "u32str = ";
for (auto c : u32str)
{
std::cout << c << " ";
}
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment