Convert UTF-8 to 32-bit Unicode first.
Then save the values between 0 and 255.
These are Latin-1 code points, and for other values, decide whether you want to treat this as an error or perhaps replace it with code 127 (my fav, ASCII "del") or a question mark or something else.
The C ++ Standard Library defines the specialization std::codecvt that can be used,
template<> codecvt<char32_t, char, mbstate_t>
C ++ 11 §22.4.1.4 / 3 : "the specialization codecvt <char32_t, char, mbstate_t> converts between UTF-32 and UTF-8 encoding schemes"
source share