Why is nl_langinfo(CODESET) different from locale

2019-05-13 21:22发布

问题:

This post originated from How do you get what kind of encoding your system uses in c/c++?

I tried using

nl_langinfo(CODESET)

but I got ANSI_X3.4-1968 instead of UTF-8 (which is what I get when typing: locale charmap). Am I using nl_langinfo() wrong? How should I use it?

回答1:

You need to first call

setlocale(LC_ALL, "");

nl_langinfo always gives information about the current locale.



标签: c++ c locale