I'm trying convert some strings from ASCII to UTF8.
And, i searched many things, but i can't found it.
So i coded this.
std::string ASCII("ASCII string");
auto utf8 = boost::locale::conv::to_utf<char>(ansi, std::locale("en_US.UTF8"));
Is this right? on my system this is dosen't work.
Please, help me.
Thanks.
If you mean conversion from your system locale to utf8 or vice versa, we use the following which is working well:
static std::string fromLocale(const std::string &localeStr){
boost::locale::generator g;
g.locale_cache_enabled(true);
std::locale loc = g(boost::locale::util::get_system_locale());
return boost::locale::conv::to_utf<char>(localeStr,loc);
}
static std::string toLocale(const std::string &utf8Str){
boost::locale::generator g;
g.locale_cache_enabled(true);
std::locale loc = g(boost::locale::util::get_system_locale());
return boost::locale::conv::from_utf<char>(utf8Str,loc);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With