关于区域设置的问题 [英] question about locale

查看:86
本文介绍了关于区域设置的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请说明在c ++中使用locale的目的?我已阅读文档,但不要uderstand请帮助

please explain purpose of usage of locale in c++? i have read documents but dont uderstand please help

推荐答案

基本目的是本地化应用程序。例如,在美国,带有小数分隔符的大数字通常写成:1,234.56。在欧洲大部分地区,相同的数字通常写成:1.234,56。

The basic purpose is for localizing applications. For example, in the US a large number with a decimal separator would normally be written like: "1,234.56". Throughout much of Europe the same number would normally be written like: "1.234,56".

区域设置允许您隔离有关此类格式的信息国家之间,语言,文化等)到一个地方。例如,我可以使用:

A locale allows you to isolate information about such formatting (and other things that vary between countries, languages, cultures, etc.) into one place. For example, I might use:

std::locale loc("");
std::cout.imbue(loc);

std::cout << 1234.56;

未命名的语言环境()是特殊的:它会自动选择用户配置的语言环境。当我运行这个代码,我得到的输出是:1,234.56。其他人可以运行完全相同的代码,但是如果他们的环境配置了一些其他约定,他们可能会得到1.234,56或1 234,56等。

The unnamed locale ("") is special: it automatically picks out whatever locale the user has configured. When I run this code, the output I get is: "1,234.56". Somebody else could run exactly the same code, but if their environment was configured for some other convention, they might get "1.234,56" or "1 234,56", etc.

所以,区域设置购买我们的大部分(在这种情况下)是保持写一个数字单独格式化该数字适合特定的观众。当然,区域设置具有多个facet,每个都包括单独的... well,本地化的方面,例如格式化数字,格式化货币,确定什么被认为是小写或大写字母等。

So, most of what the locale buys us (in this case) is keeping writing a number separate from formatting that number appropriately for a specific audience. Of course, a locale has a number of "facets", each of which covers a separate...well, facet of localization, such as formatting numbers, formatting currency, determining what's considered a lower-case or upper-case letter, etc.

这篇关于关于区域设置的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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