Skip to content

Instantly share code, notes, and snippets.

@islishude
Created June 11, 2019 02:08
Show Gist options
  • Save islishude/08c10e3e52ec6f649ce3925a81f6345e to your computer and use it in GitHub Desktop.
Save islishude/08c10e3e52ec6f649ce3925a81f6345e to your computer and use it in GitHub Desktop.
utf8 iterator for cpp
#include <codecvt>
#include <locale>
#include <iostream>
#include <string>
int main()
{
std::u32string input = U"这是中文";
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
for (char32_t c : input)
{
std::cout << converter.to_bytes(c) << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment