Skip to content

Instantly share code, notes, and snippets.

@remyroez
Created November 1, 2016 00:32
Show Gist options
  • Save remyroez/ff7e7094a503cd2034d0b156be46508c to your computer and use it in GitHub Desktop.
Save remyroez/ff7e7094a503cd2034d0b156be46508c to your computer and use it in GitHub Desktop.
UTF32 版 stringstream
#include <iostream>
#include <sstream>
#include <string>
#include <locale>
#include <codecvt>
using w32stringstream = std::basic_stringstream<char32_t>;
int main()
{
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
std::string u8str = u8"あいうえお";
std::u32string u32str = converter.from_bytes(u8str);
std::cout << "u32str = ";
for (auto c : u32str)
{
std::cout << c << " ";
}
std::cout << std::endl;
w32stringstream ss;
ss << u32str;
std::u32string foo = ss.str();
std::cout << "foo = ";
for (auto c : foo)
{
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