你如何得到你的系统在c / c ++中使用什么样的编码? [英] How do you get what kind of encoding your system uses in c/c++?

查看:135
本文介绍了你如何得到你的系统在c / c ++中使用什么样的编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在linux终端中,会输入

In linux terminal one would type

locale charmap

以查看您的系统使用什么样的字符编码,例如UTF-8。
我的问题是你将如何使用c / c ++。 (我正在使用linux)

in order to see what kind of character-encoding your system uses, eg UTF-8. My question is how would you do this using c/c++. (I'm using linux)

编辑:我尝试使用

nl_langinfo(CODESET)

但我得到的是ANSI_X3.4-1968的UTF-8(这是我得到当输入:locale charmap)。我使用nl_langinfo()错了?

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?

推荐答案

SETLOCALE(3)               Linux Programmer’s Manual              SETLOCALE(3)

NAME
       setlocale - set the current locale

SYNOPSIS
       #include <locale.h>

       char *setlocale(int category, const char *locale);

DESCRIPTION
       The  setlocale() function is used to set or query the program’s current
       locale.







NL_LANGINFO(3)             Linux Programmer’s Manual            NL_LANGINFO(3)

NAME
       nl_langinfo - query language and locale information

SYNOPSIS
       #include <langinfo.h>

       char *nl_langinfo(nl_item item);

DESCRIPTION
       The  nl_langinfo()  function provides access to locale information in a
       more flexible way than localeconv(3) does.  Individual  and  additional
       elements  of  the locale categories can be queried.  setlocale(3) needs
       to be executed with proper arguments before.
       Examples for the locale elements that can be specified  in  item  using
       the constants defined in <langinfo.h> are:

       CODESET (LC_CTYPE)
          Return  a string with the name of the character encoding used in
          the  selected  locale,  such  as   "UTF-8",   "ISO-8859-1",   or
          "ANSI_X3.4-1968"  (better  known as US-ASCII).  This is the same
          string that you get with "locale charmap".  For a list of  char‐
          acter encoding names, try "locale -m", cf. locale(1).

这篇关于你如何得到你的系统在c / c ++中使用什么样的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆