The not-so-satisfactory answer is that you need to inject the input stream into a locale that understands the specific character encoding. If you donโt know which language to choose, you can use an empty language.
For example (untested):
std::wifstream a("a.txt"); std::locale loc(""); a.imbue(loc);
Unfortunately, there is no standard way to determine which locales are available for a given platform, not to mention choosing one based on character encoding.
The above code puts the choice of language in the hands of the user, and if he installs it on something believable (for example, en_AU.UTF-8 ), it can all just work.
Otherwise, you may have to go to third-party libraries such as iconv or ICU .
This blog post is also appropriate (apologies for self-promotion).
source share