如何获取您的系统在 c/c++ 中使用哪种编码?

use*_*121 1 c c++ character-encoding

在linux终端中可以输入

locale charmap
Run Code Online (Sandbox Code Playgroud)

以查看您的系统使用哪种字符编码,例如 UTF-8。我的问题是你将如何使用 c/c++ 来做到这一点。(我使用的是linux)

编辑:我尝试使用

nl_langinfo(CODESET)
Run Code Online (Sandbox Code Playgroud)

但我得到的是 ANSI_X3.4-1968 而不是 UTF-8(这是我输入:locale charmap 时得到的)。我使用 nl_langinfo() 错误吗?

Dig*_*oss 5

SETLOCALE(3)               Linux Programmer\xe2\x80\x99s Manual              SETLOCALE(3)\n\nNAME\n       setlocale - set the current locale\n\nSYNOPSIS\n       #include <locale.h>\n\n       char *setlocale(int category, const char *locale);\n\nDESCRIPTION\n       The  setlocale() function is used to set or query the program\xe2\x80\x99s current\n       locale.\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n
NL_LANGINFO(3)             Linux Programmer\xe2\x80\x99s Manual            NL_LANGINFO(3)\n\nNAME\n       nl_langinfo - query language and locale information\n\nSYNOPSIS\n       #include <langinfo.h>\n\n       char *nl_langinfo(nl_item item);\n\nDESCRIPTION\n       The  nl_langinfo()  function provides access to locale information in a\n       more flexible way than localeconv(3) does.  Individual  and  additional\n       elements  of  the locale categories can be queried.  setlocale(3) needs\n       to be executed with proper arguments before.\n       Examples for the locale elements that can be specified  in  item  using\n       the constants defined in <langinfo.h> are:\n\n       CODESET (LC_CTYPE)\n          Return  a string with the name of the character encoding used in\n          the  selected  locale,  such  as   "UTF-8",   "ISO-8859-1",   or\n          "ANSI_X3.4-1968"  (better  known as US-ASCII).  This is the same\n          string that you get with "locale charmap".  For a list of  char\xe2\x80\x90\n          acter encoding names, try "locale -m", cf. locale(1).\n
Run Code Online (Sandbox Code Playgroud)\n