std::use_facet

来自cppreference.com

 
 
本地化库
语言环境方面
Original:
Locales and facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
locale
use_facet
字符分类
Original:
Character classification
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
转换
Original:
Conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
wstring_convert(C++11)
wbuffer_convert(C++11)
小面类的基类
Original:
Facet category base classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
小面类
Original:
Facet categories
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
特定于语言环境的方面
Original:
Locale-specific facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代码转换方面
Original:
Code conversion facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
codecvt_utf8(C++11)
codecvt_utf16(C++11)
codecvt_utf8_utf16(C++11)
codecvt_mode(C++11)
C语言环境
Original:
C locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <locale>
template< class Facet >
const Facet& use_facet( const std::locale& loc );
获得一个参考的一个方面实施loc.
Original:
Obtains a reference to a facet implemented by loc.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 参数

loc -
Locale对象来查询
Original:
the locale object to query
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 返回值

返回一个参考的方面。参考这个函数返回的是有效的,只要存在任何std::locale对象,实现Facet.
Original:
Returns a reference the facet. The reference returned by this function is valid as long as any std::locale object exists that implements Facet.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 例外

std::bad_cast if std::has_facet<Facet>(loc) == false.

[编辑] 为例

显示3个字母的货币名称由用户的首选区域
Original:
Display the 3-letter currency name used by the user's preferred locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <locale>
 
int main()
{
    std::locale loc = std::locale(""); // user's preferred locale
    std::cout << "Your currency string is "
              << std::use_facet<std::moneypunct<char, true>>(loc).curr_symbol() << '\n';
}

Output:

Your currency string is USD

[编辑] 另请参阅

多态的文化差异方面的封装
Original:
set of polymorphic facets that encapsulate cultural differences
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(类) [edit]
检查如果一个语言环境中实现一个特定的方面
Original:
checks if a locale implements a specific facet
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(函数模板) [edit]