gpt4 book ai didi

c - C 中的 getlocale() 函数

转载 作者:行者123 更新时间:2023-12-01 04:34:47 25 4
gpt4 key购买 nike

我可以使用 setlocale() 设置语言环境功能。但是有什么方法可以获取语言环境并将其保存在变量中,以便以后可以重置它。

这就是我想要做的:

str=getlocale(LC_CTYPE);
setlocale(LC_CTYPE,"en_US");
...
setlocale(LC_CTYPE,str);

我该如何实现 getlocale()功能,还是有其他选择?

最佳答案

您可以通过NULL并使用返回值。见 setlocale

You can also use this function to find out the current locale by passing a null pointer as the locale argument. In this case, setlocale returns a string that is the name of the locale currently selected for category category.



或者在 C 标准中:

7.11.1.1 The setlocale function
....

If a pointer to a string is given for locale and the selection can be honored, the setlocale function returns a pointer to the string associated with the specified category for the new locale. If the selection cannot be honored, the setlocale function returns a null pointer and the program’s locale is not changed.

A null pointer for locale causes the setlocale function to return a pointer to the string associated with the category for the program’s current locale; the program’s locale is not changed.

The pointer to string returned by the setlocale function is such that a subsequent call with that string value and its associated category will restore that part of the program’s locale.

关于c - C 中的 getlocale() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34345622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com